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:Main.java

public static ResolveInfo getResolveInfo(PackageManager pm, String packageName) {
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(packageName);
    List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
    if (apps != null && apps.size() > 0) {
        return apps.get(0);
    }/*  w  w  w. j  av a  2  s.c om*/
    return null;
}

From source file:Main.java

public static void goToNaviActivity(Context context, String sourceApplication, String poiname, String lat,
        String lon, String dev, String style) {
    StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=")
            .append(sourceApplication);//from  w  w  w. ja  v  a 2s.c o  m
    if (!TextUtils.isEmpty(poiname)) {
        stringBuffer.append("&poiname=").append(poiname);
    }
    stringBuffer.append("&lat=").append(lat).append("&lon=").append(lon).append("&dev=").append(dev)
            .append("&style=").append(style);
    Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse(stringBuffer.toString()));
    intent.setPackage("com.autonavi.minimap");
    context.startActivity(intent);
}

From source file:Main.java

public static void runApp(Context context, String paramString) {
    PackageManager localPackageManager = context.getPackageManager();
    try {//from   w w w  .  j a v a 2 s.  c o m
        PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramString, 0);
        Intent localIntent1 = new Intent("android.intent.action.MAIN", null);
        localIntent1.setPackage(localPackageInfo.packageName);
        ResolveInfo localResolveInfo = (ResolveInfo) localPackageManager.queryIntentActivities(localIntent1, 0)
                .iterator().next();
        if (localResolveInfo != null) {
            String str1 = localResolveInfo.activityInfo.packageName;
            String str2 = localResolveInfo.activityInfo.name;
            Intent localIntent2 = new Intent("android.intent.action.MAIN");
            localIntent2.setComponent(new ComponentName(str1, str2));
            context.startActivity(localIntent2);
        }
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
        localNameNotFoundException.printStackTrace();
    }
}

From source file:Main.java

/**
 * Find out if K-9 Mail is enabled, i.e. an account was set up.
 *
 * @param context//www  .  j a va 2  s.co  m
 *         Used to retrieve the package manager.
 *
 * @return {@code true} if K-9 Mail is enabled, {@code false} otherwise.
 */
public static final boolean isK9Enabled(Context context) {
    PackageManager manager = context.getPackageManager();
    try {
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
        intent.setPackage(PACKAGE_NAME);
        List<ResolveInfo> results = manager.queryIntentActivities(intent, 0);
        return (results != null && results.size() > 0);
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static String getAppMainActivity(Context context, String packageName) {
    if (TextUtils.isEmpty(packageName)) {
        return "";
    }/*from w  ww .  j av  a  2s .c  o m*/
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(packageName);
    final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
    if (res == null || res.activityInfo == null) {
        return "";
    }
    return res.activityInfo.name;
}

From source file:Main.java

public static boolean isLauncherActivity(Context context, String packageName) {
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    mainIntent.setPackage(packageName);
    List<ResolveInfo> infoList = context.getPackageManager().queryIntentActivities(mainIntent, 0);
    if (infoList.isEmpty()) {
        return false;
    } else {/*from  w  ww  . j a  va 2s . c om*/
        return true;
    }
}

From source file:com.yalin.fidoclient.asm.api.ASMApi.java

public static void doOperation(Fragment fragment, int requestCode, String asmMessage, String pack) {
    if (TextUtils.isEmpty(asmMessage)) {
        throw new IllegalArgumentException("asmMessage can not be null");
    }/*from w w w.  j  av  a 2s . co  m*/
    Intent intent = ASMIntent.getASMOperationIntent(asmMessage);
    if (!TextUtils.isEmpty(pack)) {
        intent.setPackage(pack);
    }
    fragment.startActivityForResult(intent, requestCode);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
public static List<String> getCustomTabSupportingPackages(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }/*from w w  w.j  av a  2 s  . c o m*/
    }
    return packagesSupportingCustomTabs;
}

From source file:Main.java

public static void exitGapdeApp_auto(Context context) {
    Intent intent = new Intent("android.intent.action.VIEW",
            android.net.Uri.parse("androidauto://appExit?sourceApplication=launcher"));
    intent.setPackage("com.autonavi.amapauto");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*www  .j  av  a 2  s.c o m*/
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;//from w  ww.j  a va  2  s.c o  m
    try {
        pi = pm.getPackageInfo(packageName, 0);
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setPackage(pi.packageName);

        List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);

        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            String className = ri.activityInfo.name;
            intent.setComponent(new ComponentName(packageName, className));
            ctx.startActivity(intent);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}