diff options
author | Nick Pelly <npelly@google.com> | 2011-07-12 14:50:18 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-12 14:50:18 -0700 |
commit | 4f7fd877ad07949ded0d4e9e126852ad84daab92 (patch) | |
tree | 89a743148a38383c9660c3ea60104697d4fdb059 /src | |
parent | 6ec87aa54aad2c340c4ea0247ba4a8e0d9f10573 (diff) | |
parent | b442e5fc49f235c228d3989c73e333d58caa2ade (diff) | |
download | packages_apps_nfc-4f7fd877ad07949ded0d4e9e126852ad84daab92.zip packages_apps_nfc-4f7fd877ad07949ded0d4e9e126852ad84daab92.tar.gz packages_apps_nfc-4f7fd877ad07949ded0d4e9e126852ad84daab92.tar.bz2 |
Merge "Allow dispatch to a specific package"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/nfc/NfcDispatcher.java | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/com/android/nfc/NfcDispatcher.java b/src/com/android/nfc/NfcDispatcher.java index 2e10091..8c359a7 100644 --- a/src/com/android/nfc/NfcDispatcher.java +++ b/src/com/android/nfc/NfcDispatcher.java @@ -47,6 +47,7 @@ import java.util.Arrays; * Dispatch of NFC events to start activities */ public class NfcDispatcher { + public static final byte[] RTD_ANDROID_APP = "android.com:pkg".getBytes(); private static final boolean DBG = NfcService.DBG; private static final String TAG = NfcService.TAG; @@ -167,7 +168,7 @@ public class NfcDispatcher { if (setTypeOrDataFromNdef(intent, record)) { // The record contains filterable data, try to start a matching activity if (startDispatchActivity(intent, overrideIntent, overrideFilters, - overrideTechLists)) { + overrideTechLists, records)) { // If an activity is found then skip further dispatching return true; } else { @@ -249,7 +250,8 @@ public class NfcDispatcher { // Try the generic intent // intent = buildTagIntent(tag, msgs, NfcAdapter.ACTION_TAG_DISCOVERED); - if (startDispatchActivity(intent, overrideIntent, overrideFilters, overrideTechLists)) { + if (startDispatchActivity(intent, overrideIntent, overrideFilters, overrideTechLists, + null)) { return true; } else { Log.e(TAG, "No tag fallback activity found for " + intent); @@ -258,7 +260,7 @@ public class NfcDispatcher { } private boolean startDispatchActivity(Intent intent, PendingIntent overrideIntent, - IntentFilter[] overrideFilters, String[][] overrideTechLists) + IntentFilter[] overrideFilters, String[][] overrideTechLists, NdefRecord[] records) throws CanceledException { if (overrideIntent != null) { boolean found = false; @@ -289,6 +291,41 @@ public class NfcDispatcher { // resumeAppSwitches() mIActivityManager.resumeAppSwitches(); } catch (RemoteException e) { } + if (records != null) { + String firstPackage = null; + for (NdefRecord record : records) { + if (record.getTnf() == NdefRecord.TNF_EXTERNAL_TYPE) { + if (Arrays.equals(record.getType(), RTD_ANDROID_APP)) { + String pkg = new String(record.getPayload(), Charsets.US_ASCII); + if (firstPackage == null) { + firstPackage = pkg; + } + intent.setPackage(pkg); + try { + mContext.startActivity(intent); + return true; + } catch (ActivityNotFoundException e) { + // Continue; there may be another match. + } + } + } + } + if (firstPackage != null) { + // Found an Android package, but could not handle ndef intent. + // If the application is installed, call its main activity. + try { + Intent main = new Intent(Intent.ACTION_MAIN); + main.addCategory(Intent.CATEGORY_LAUNCHER); + main.setPackage(firstPackage); + mContext.startActivity(main); + return true; + } catch (ActivityNotFoundException e) { + Intent market = getAppSearchIntent(firstPackage); + mContext.startActivity(market); + return true; + } + } + } try { mContext.startActivity(intent); return true; @@ -371,6 +408,16 @@ public class NfcDispatcher { } } + /** + * Returns an intent that can be used to find an application not currently + * installed on the device. + */ + private static Intent getAppSearchIntent(String pkg) { + Intent market = new Intent(Intent.ACTION_VIEW); + market.setData(Uri.parse("market://details?id=" + pkg)); + return market; + } + private static boolean isComponentEnabled(PackageManager pm, ResolveInfo info) { boolean enabled = false; ComponentName compname = new ComponentName( |