Example usage for android.content Intent setPackage

List of usage examples for android.content Intent setPackage

Introduction

In this page you can find the example usage for android.content Intent setPackage.

Prototype

public @NonNull Intent setPackage(@Nullable String packageName) 

Source Link

Document

(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to.

Usage

From source file:androidx.media.SessionToken2.java

private static String getSessionIdFromService(PackageManager manager, String serviceInterface,
        ComponentName serviceComponent) {
    Intent serviceIntent = new Intent(serviceInterface);
    // Use queryIntentServices to find services with MediaLibraryService2.SERVICE_INTERFACE.
    // We cannot use resolveService with intent specified class name, because resolveService
    // ignores actions if Intent.setClassName() is specified.
    serviceIntent.setPackage(serviceComponent.getPackageName());

    List<ResolveInfo> list = manager.queryIntentServices(serviceIntent, PackageManager.GET_META_DATA);
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            ResolveInfo resolveInfo = list.get(i);
            if (resolveInfo == null || resolveInfo.serviceInfo == null) {
                continue;
            }//from w w w. ja  va  2 s. co m
            if (TextUtils.equals(resolveInfo.serviceInfo.name, serviceComponent.getClassName())) {
                return getSessionId(resolveInfo);
            }
        }
    }
    return null;
}

From source file:org.dmfs.tasks.notification.NotificationActionUtils.java

/**
 * Creates a {@link PendingIntent} for the specified notification action.
 *///from   ww w .  ja  v a 2s  .  com
public static PendingIntent getNotificationActionPendingIntent(Context context, NotificationAction action) {
    final Intent intent = new Intent(context, NotificationUpdaterService.class);
    intent.setAction(action.getActionType());
    intent.setData(action.getTaskUri());
    intent.setPackage(context.getPackageName());
    putNotificationActionExtra(intent, action);

    return PendingIntent.getService(context, action.getNotificationId(), intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:mobisocial.socialkit.musubi.Musubi.java

public static boolean isMusubiInstalled(Context context) {
    try {//from   w w w  .  j  a  v a  2  s  .  c  o m
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setPackage(SUPER_APP_ID);
        return context.getPackageManager().queryIntentActivities(intent, 0).size() > 0;
    } catch (Throwable t) {
        return false;
    }
}

From source file:arun.com.chromer.browsing.customtabs.CustomTabs.java

/**
 * Determines if the provided package name is a valid custom tab provider or not.
 *
 * @param context     Context to work with
 * @param packageName Package name of the app
 * @return true if a provider, false otherwise
 *///from  w  w w .  j  a v a 2s.c om
public static boolean isPackageSupportCustomTabs(Context context, @Nullable String packageName) {
    if (packageName == null) {
        return false;
    }
    final PackageManager pm = context.getApplicationContext().getPackageManager();
    final Intent serviceIntent = new Intent();
    serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
    serviceIntent.setPackage(packageName);
    return pm.resolveService(serviceIntent, 0) != null;
}

From source file:au.id.micolous.frogjump.Util.java

public static void navigateTo(int latE6, int lngE6, MainActivity.NavigationMode navigationMode,
        Context context) {/*from w w w .j  av a 2s  .c  om*/
    // Lets make that a decimal again
    String geoloc = String.format("%1$d.%2$06d,%3$d.%4$06d", latE6 / 1000000, Math.abs(latE6 % 1000000),
            lngE6 / 1000000, Math.abs(lngE6 % 1000000));

    Intent intent = null;
    if (navigationMode == MainActivity.NavigationMode.CROW_FLIES
            || navigationMode == MainActivity.NavigationMode.SHOW_MAP) {
        geoloc = "geo:" + geoloc + "?q=" + geoloc;
        Uri geouri = Uri.parse(geoloc);
        intent = new Intent(Intent.ACTION_VIEW, geouri);
        if (navigationMode == MainActivity.NavigationMode.CROW_FLIES) {
            intent.setPackage(GPS_STATUS);
        }
    } else if (navigationMode != MainActivity.NavigationMode.OFF) {
        geoloc = "google.navigation:q=" + geoloc;
        switch (navigationMode) {
        // https://developers.google.com/maps/documentation/directions/intro#Restrictions
        // The intent service supports this parameter too, but it is not documented.
        case DRIVING_AVOID_TOLLS:
            geoloc += "&avoid=tolls";
        case DRIVING:
            geoloc += "&mode=d";
            break;
        case CYCLING:
            geoloc += "&mode=b";
            break;
        case WALKING:
            geoloc += "&mode=w";
            break;
        }

        // Launch Google Maps
        Uri geouri = Uri.parse(geoloc);
        intent = new Intent(Intent.ACTION_VIEW, geouri);
        intent.setPackage(GOOGLE_MAPS);
    }

    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}

From source file:com.android.mail.widget.WidgetService.java

public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId,
        Account account, final int folderType, final int folderCapabilities, final Uri folderUri,
        final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) {
    remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE);

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, serviceClass);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri);
    intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
    // Open mail app when click on header
    final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account);
    mailIntent.setPackage(context.getPackageName());
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent();
    composeIntent.setPackage(context.getPackageName());
    composeIntent.setAction(Intent.ACTION_SEND);
    composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize());
    composeIntent.setData(account.composeIntentUri);
    composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true);
    if (account.composeIntentUri != null) {
        composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri);
    }//from w ww. j ava 2  s  . c o m

    // Build a task stack that forces the conversation list on the stack before the compose
    // activity.
    final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    final Intent conversationIntent = new Intent();
    conversationIntent.setPackage(context.getPackageName());
    conversationIntent.setAction(Intent.ACTION_VIEW);
    clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent);
}

From source file:com.popdeem.sdk.core.utils.PDSocialUtils.java

/**
 * Create a chooser Intent for sharing an Image file to Instagram
 *
 * @param path Path to Image file/*from w  ww  .jav a  2 s  . c  o m*/
 * @return Chooser Intent
 */
public static Intent createInstagramIntent(Context context, String path) {
    File file = new File(path);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/*");
    intent.setPackage("com.instagram.android");
    Log.i("PROVIDER", "createInstagramIntent: ");
    Uri sharedFileUri = FileProvider.getUriForFile(context,
            context.getApplicationContext().getPackageName() + ".fileprovider", file);

    intent.putExtra(Intent.EXTRA_STREAM, sharedFileUri);
    return intent;
    //        return Intent.createChooser(intent, "Share to");
}

From source file:Main.java

/**
 * Intent chooser is customized to remove unwanted apps.
 * 1. FaceBook has bug where only links can be shared.
 * 2. Cannot share this type of content via Google Docs and Skype.
 *//*ww  w  . j a v  a  2  s. c om*/
public static void ShareResult(Context mContext, String mResult, String mTitle) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    List<ResolveInfo> resInfo = mContext.getPackageManager().queryIntentActivities(shareIntent, 0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;
            Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
            targetedShareIntent.setType("text/plain");
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mTitle);
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_TITLE, mTitle);
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mResult);
            if (!packageName.toLowerCase().contains("com.facebook.katana")
                    && !packageName.toLowerCase().contains("com.google.android.apps.docs")
                    && !packageName.toLowerCase().contains("com.skype.raider")) {
                targetedShareIntent.setPackage(packageName);
                targetedShareIntents.add(targetedShareIntent);
            }
        }
        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Send your result");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
        mContext.startActivity(chooserIntent);
    }
    return;
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View Whats App profile//w w w.ja  v a  2s . c  o  m
 *
 * @param activity context
 * @param address  whats app number
 */
public static void launchWhatsAppIntent(Activity activity, String address) {
    Intent intent = new Intent();
    intent.setPackage("com.whatsapp");
    intent.setData(Uri.parse("smsto:" + address));
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java

private static PendingIntent getDelayActionIntent(Context context, int notificationId, Uri taskUri, long due,
        boolean delay1h, String timezone, boolean allday) {
    String action = null;//from   w ww . jav  a2 s .  c  om
    if (delay1h) {
        action = ACTION_DELAY_1H;
    } else {
        action = ACTION_DELAY_1D;
    }
    final Intent intent = new Intent(context, NotificationUpdaterService.class);
    intent.setAction(action);
    intent.setPackage(context.getPackageName());
    intent.setData(taskUri);
    intent.putExtra(EXTRA_TASK_DUE, due);
    intent.putExtra(EXTRA_TIMEZONE, timezone);
    intent.putExtra(EXTRA_ALLDAY, allday);
    intent.putExtra(EXTRA_NOTIFICATION_ID, notificationId);
    final PendingIntent pendingIntent = PendingIntent.getService(context, REQUEST_CODE_DELAY, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    return pendingIntent;
}