Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

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

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:Main.java

public static void openAppDetails(Context context, String pkgname) {
    Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    Uri data = Uri.parse("package:" + pkgname);
    i.setData(data);//from   ww  w .  j a  va 2s . co  m
    context.startActivity(i);
}

From source file:Main.java

public static String getLauncherClassName(Context context) {

    PackageManager pm = context.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo resolveInfo : resolveInfos) {
        String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
        if (pkgName.equalsIgnoreCase(context.getPackageName())) {
            String className = resolveInfo.activityInfo.name;
            return className;
        }// w ww  . j a va  2s.co  m
    }
    return null;
}

From source file:Main.java

public static Intent toRootPermission() {
    Intent intent = new Intent();
    intent.setAction("miui.intent.action.ROOT_MANAGER");
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    return intent;
}

From source file:Main.java

public static void shareApkInfo(String info, Context context) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.SEND");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, info);
    context.startActivity(intent);/*  w  w w.  ja  v a  2 s .  c  o  m*/
}

From source file:Main.java

public static void choosePicFromGalley(Context context) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);//ACTION_OPEN_DOCUMENT
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/jpeg");

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        ((Activity) context).startActivityForResult(intent, CHOOSE_GALLERY);
    } else {/* ww  w  . j  a  v  a 2 s . co  m*/
        ((Activity) context).startActivityForResult(intent, CHOOSE_GALLERY);
    }
}

From source file:Main.java

public static Intent toAutoStartPermission() {
    Intent intent = new Intent();
    intent.setAction("miui.intent.action.OP_AUTO_START");
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    return intent;
}

From source file:Main.java

public static void uninstallApp(String packageName, Activity activity) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.DELETE");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setData(Uri.parse("package:" + packageName));
    activity.startActivityForResult(intent, 0);
}

From source file:Main.java

public static void takeMyselfToForeground(Context context, Class launcher) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(context, launcher);//from   w w  w .j a  va 2 s  .co  m
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(intent);
}

From source file:Main.java

public static String getLauncherClassName(Context context) {
    PackageManager pm = context.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo resolveInfo : resolveInfos) {
        String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
        if (pkgName.equalsIgnoreCase(context.getPackageName())) {
            String className = resolveInfo.activityInfo.name;
            return className;
        }//ww w. j  a  v a2 s. c o m
    }
    return null;
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;//  w w w  . j av  a2 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();
    }
}