Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/227369
Change subject: Fix app picker on older devices ...................................................................... Fix app picker on older devices - Specify appropriate resource package name. - Set intent package name. - Specify some function invariant annotations. This patch was derived from behavior on actual devices rather than documentation. Bug: T106332 Change-Id: Ibbcc0f669f196e8e27c3e828a8305af969429596 --- M wikipedia/src/main/java/org/wikipedia/Utils.java M wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java 2 files changed, 22 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/69/227369/1 diff --git a/wikipedia/src/main/java/org/wikipedia/Utils.java b/wikipedia/src/main/java/org/wikipedia/Utils.java index 2fce3d0..22e9ed4 100644 --- a/wikipedia/src/main/java/org/wikipedia/Utils.java +++ b/wikipedia/src/main/java/org/wikipedia/Utils.java @@ -361,11 +361,8 @@ * @param uri URI to open in an external browser */ public static void visitInExternalBrowser(final Context context, Uri uri) { - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); - intent.setData(uri); - - Intent chooserIntent = ShareUtils.createChooserIntent(intent, null, context); + Intent chooserIntent = ShareUtils.createChooserIntent(new Intent(Intent.ACTION_VIEW, uri), + null, context); if (chooserIntent == null) { // This means that there was no way to handle this link. // We will just show a toast now. FIXME: Make this more visible? diff --git a/wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java b/wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java index 3201dac..56a5781 100644 --- a/wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java +++ b/wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.os.Environment; import android.os.Parcelable; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; import android.widget.Toast; @@ -156,18 +157,18 @@ } @Nullable - public static Intent createChooserIntent(Intent targetIntent, - CharSequence chooserTitle, - Context context) { + public static Intent createChooserIntent(@NonNull Intent targetIntent, + @Nullable CharSequence chooserTitle, + @NonNull Context context) { return createChooserIntent(targetIntent, chooserTitle, context, APP_PACKAGE_REGEX); } @Nullable - public static Intent createChooserIntent(Intent targetIntent, - CharSequence chooserTitle, - Context context, + public static Intent createChooserIntent(@NonNull Intent targetIntent, + @Nullable CharSequence chooserTitle, + @NonNull Context context, String packageNameBlacklistRegex) { - List<LabeledIntent> intents = queryIntents(context, targetIntent, packageNameBlacklistRegex); + List<Intent> intents = queryIntents(context, targetIntent, packageNameBlacklistRegex); if (intents.isEmpty()) { return null; @@ -175,13 +176,13 @@ Intent bestIntent = intents.remove(0); return Intent.createChooser(bestIntent, chooserTitle) - .putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[0])); + .putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()])); } - public static List<LabeledIntent> queryIntents(Context context, - Intent targetIntent, - String packageNameBlacklistRegex) { - List<LabeledIntent> intents = new ArrayList<>(); + public static List<Intent> queryIntents(@NonNull Context context, + @NonNull Intent targetIntent, + String packageNameBlacklistRegex) { + List<Intent> intents = new ArrayList<>(); for (ResolveInfo intentActivity : queryIntentActivities(targetIntent, context)) { if (!isIntentActivityBlacklisted(intentActivity, packageNameBlacklistRegex)) { intents.add(buildLabeledIntent(targetIntent, intentActivity)); @@ -190,24 +191,26 @@ return intents; } - public static List<ResolveInfo> queryIntentActivities(Intent intent, Context context) { + public static List<ResolveInfo> queryIntentActivities(Intent intent, @NonNull Context context) { return context.getPackageManager().queryIntentActivities(intent, 0); } - private static boolean isIntentActivityBlacklisted(ResolveInfo intentActivity, - String packageNameBlacklistRegex) { + private static boolean isIntentActivityBlacklisted(@Nullable ResolveInfo intentActivity, + @Nullable String packageNameBlacklistRegex) { return intentActivity != null && getPackageName(intentActivity).matches(emptyIfNull(packageNameBlacklistRegex)); } private static LabeledIntent buildLabeledIntent(Intent intent, ResolveInfo intentActivity) { - LabeledIntent labeledIntent = new LabeledIntent(intent, getPackageName(intentActivity), + + LabeledIntent labeledIntent = new LabeledIntent(intent, intentActivity.resolvePackageName, intentActivity.labelRes, intentActivity.getIconResource()); + labeledIntent.setPackage(getPackageName(intentActivity)); labeledIntent.setClassName(getPackageName(intentActivity), intentActivity.activityInfo.name); return labeledIntent; } - private static String getPackageName(ResolveInfo intentActivity) { + private static String getPackageName(@NonNull ResolveInfo intentActivity) { return intentActivity.activityInfo.packageName; } } -- To view, visit https://gerrit.wikimedia.org/r/227369 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibbcc0f669f196e8e27c3e828a8305af969429596 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits