Java Examples

The following examples show how to use 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 Project: 10000sentences   Author: tkrajina   File:    License: Apache License 2.0 6 votes vote down vote up
 * 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.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,;
            intent.putExtra(android.content.Intent.EXTRA_TEXT, text);
            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);
Example #2
Source Project: mollyim-android   Author: mollyim   File:    License: GNU General Public License v3.0 5 votes vote down vote up
 * From: <a href=""></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();

    return new LabeledIntent(resolved, context.getPackageName(), name, drawable);
  return null;