Last active
August 29, 2015 14:01
-
-
Save GBouerat/13dbb5b1a8170d0c8cad to your computer and use it in GitHub Desktop.
Filtering Intent chooser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uri uri = Uri.parse("http://WTF") | |
Intent intent = new Intent(Intent.ACTION_VIEW, uri); | |
List<ResolveInfo> resolveInfos = getActivity().getPackageManager().queryIntentActivities(intent, 0); | |
if (!resolveInfos.isEmpty()) { | |
ArrayList<Intent> intents = new ArrayList<Intent>(resolveInfos.size() - 1); | |
for (ResolveInfo resolveInfo : resolveInfos) { | |
String packageName = resolveInfo.activityInfo.packageName; | |
if (TextUtils.equals(packageName, BuildConfig.PACKAGE_NAME)) { | |
continue; | |
} | |
Intent target = new Intent(Intent.ACTION_VIEW, uri); | |
target.setPackage(packageName); | |
intents.add(target); | |
} | |
Intent chooserIntent = Intent.createChooser(intents.remove(0), "Fucking title"); | |
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()])); | |
startActivity(chooserIntent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/android/platform_frameworks_base/blob/8d21bdb90573ec48491c44eca312c162e262298d/core/java/com/android/internal/app/ChooserActivity.java