android.content.pm.LabeledIntent Java Examples
The following examples show how to use
android.content.pm.LabeledIntent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShareUtils.java From 10000sentences with Apache License 2.0 | 6 votes |
/** * Share with other applications (but tries to put applications with "Translate" in the package * name in the first place(s). */ public static void shareWithTranslate(Activity activity, String text) { Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text); PackageManager pm = activity.getPackageManager(); List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0); List<LabeledIntent> intentList = new ArrayList<>(); for (ResolveInfo ri : resInfo) { if(ri.activityInfo.packageName.contains("translate")) { Intent intent = new Intent(); intent.setComponent(new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name)); intent.putExtra(android.content.Intent.EXTRA_TEXT, text); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intentList.add(new LabeledIntent(intent, ri.activityInfo.packageName, ri.loadLabel(pm), ri.icon)); } } LabeledIntent[] extraIntents = intentList.toArray( new LabeledIntent[ intentList.size() ]); Intent openInChooser = Intent.createChooser(sendIntent, "Translate"); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); activity.startActivity(openInChooser); }
Example #2
Source File: IntentUtils.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
/** * From: <a href="https://stackoverflow.com/a/12328282">https://stackoverflow.com/a/12328282</a> */ public static @Nullable LabeledIntent getLabelintent(@NonNull Context context, @NonNull Intent origIntent, int name, int drawable) { PackageManager pm = context.getPackageManager(); ComponentName launchName = origIntent.resolveActivity(pm); if (launchName != null) { Intent resolved = new Intent(); resolved.setComponent(launchName); resolved.setData(origIntent.getData()); return new LabeledIntent(resolved, context.getPackageName(), name, drawable); } return null; }