summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBen Dodson <bjdodson@google.com>2011-07-06 10:48:27 -0700
committerBen Dodson <bjdodson@google.com>2011-07-11 15:12:03 -0700
commitb442e5fc49f235c228d3989c73e333d58caa2ade (patch)
tree3dd086b0c70061771b2ba21a316c3daece5842e6 /src
parent1299bfa9e16265e34f7e70066831c8a1fcb26479 (diff)
downloadpackages_apps_nfc-b442e5fc49f235c228d3989c73e333d58caa2ade.zip
packages_apps_nfc-b442e5fc49f235c228d3989c73e333d58caa2ade.tar.gz
packages_apps_nfc-b442e5fc49f235c228d3989c73e333d58caa2ade.tar.bz2
Allow dispatch to a specific package
Change-Id: I511dd319dd1568ef7b59621b30a2ff144978e69c
Diffstat (limited to 'src')
-rw-r--r--src/com/android/nfc/NfcDispatcher.java53
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(