From f34b34ad1004def28f367df100cb1dae05d4e331 Mon Sep 17 00:00:00 2001 From: "srowen@gmail.com" Date: Sat, 22 Jun 2013 14:51:08 +0000 Subject: [PATCH] Respect order of target apps in deciding which to invoke git-svn-id: https://zxing.googlecode.com/svn/trunk@2825 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../integration/android/IntentIntegrator.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java index d9704a562..3eea8b465 100644 --- a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java +++ b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java @@ -132,9 +132,9 @@ public class IntentIntegrator { public static final List TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE); public static final List TARGET_ALL_KNOWN = list( - BS_PACKAGE, // Barcode Scanner - BSPLUS_PACKAGE, // Barcode Scanner+ - BSPLUS_PACKAGE + ".simple" // Barcode Scanner+ Simple + BSPLUS_PACKAGE, // Barcode Scanner+ + BSPLUS_PACKAGE + ".simple", // Barcode Scanner+ Simple + BS_PACKAGE // Barcode Scanner // What else supports this intent? ); @@ -272,8 +272,7 @@ public class IntentIntegrator { } /** - * Start an activity.
- * This method is defined to allow different methods of activity starting for + * Start an activity. This method is defined to allow different methods of activity starting for * newer versions of Android and for compatibility library. * * @param intent Intent to start. @@ -289,15 +288,24 @@ public class IntentIntegrator { PackageManager pm = activity.getPackageManager(); List availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (availableApps != null) { - for (ResolveInfo availableApp : availableApps) { - String packageName = availableApp.activityInfo.packageName; - if (targetApplications.contains(packageName)) { - return packageName; + for (String targetApp : targetApplications) { + if (contains(availableApps, targetApp)) { + return targetApp; } } } return null; } + + private static boolean contains(Iterable availableApps, String targetApp) { + for (ResolveInfo availableApp : availableApps) { + String packageName = availableApp.activityInfo.packageName; + if (targetApp.equals(packageName)) { + return true; + } + } + return false; + } private AlertDialog showDownloadDialog() { AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);