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
This commit is contained in:
srowen@gmail.com 2013-06-22 14:51:08 +00:00
parent bacf3467cf
commit f34b34ad10

View file

@ -132,9 +132,9 @@ public class IntentIntegrator {
public static final List<String> TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE); public static final List<String> TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE);
public static final List<String> TARGET_ALL_KNOWN = list( public static final List<String> TARGET_ALL_KNOWN = list(
BS_PACKAGE, // Barcode Scanner BSPLUS_PACKAGE, // Barcode Scanner+
BSPLUS_PACKAGE, // Barcode Scanner+ BSPLUS_PACKAGE + ".simple", // Barcode Scanner+ Simple
BSPLUS_PACKAGE + ".simple" // Barcode Scanner+ Simple BS_PACKAGE // Barcode Scanner
// What else supports this intent? // What else supports this intent?
); );
@ -272,8 +272,7 @@ public class IntentIntegrator {
} }
/** /**
* Start an activity.<br> * Start an activity. This method is defined to allow different methods of activity starting for
* This method is defined to allow different methods of activity starting for
* newer versions of Android and for compatibility library. * newer versions of Android and for compatibility library.
* *
* @param intent Intent to start. * @param intent Intent to start.
@ -289,15 +288,24 @@ public class IntentIntegrator {
PackageManager pm = activity.getPackageManager(); PackageManager pm = activity.getPackageManager();
List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (availableApps != null) { if (availableApps != null) {
for (ResolveInfo availableApp : availableApps) { for (String targetApp : targetApplications) {
String packageName = availableApp.activityInfo.packageName; if (contains(availableApps, targetApp)) {
if (targetApplications.contains(packageName)) { return targetApp;
return packageName;
} }
} }
} }
return null; return null;
} }
private static boolean contains(Iterable<ResolveInfo> availableApps, String targetApp) {
for (ResolveInfo availableApp : availableApps) {
String packageName = availableApp.activityInfo.packageName;
if (targetApp.equals(packageName)) {
return true;
}
}
return false;
}
private AlertDialog showDownloadDialog() { private AlertDialog showDownloadDialog() {
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity); AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);