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 boolean isHaveMarket(Context getContext) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.APP_MARKET");
    PackageManager pm = getContext.getPackageManager();
    List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
    return infos.size() > 0;
}

From source file:Main.java

public static void toHome(Context context) {
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addCategory(Intent.CATEGORY_HOME);
    context.startActivity(i);//from w ww.j a  v a2s  .  com
}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;//from w  ww.  jav a2s.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 (NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * @param context/*from   w  ww . j  av  a  2s.  co m*/
 *            used to check the device version and DownloadManager
 *            information
 * @return true if the download manager is available
 */
public static boolean isDownloadManagerAvailable(Context context) {
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClassName("com.android.providers.downloads.ui",
                "com.android.providers.downloads.ui.DownloadList");
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setData(Uri.fromFile(file));/*from   www .  j  a va  2s.  c  o m*/
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

}

From source file:Main.java

public static List<ResolveInfo> getAllAppInfo(Context context) {
    try {//w  w  w  .  jav  a2s  .  co  m
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> appList = context.getPackageManager().queryIntentActivities(mainIntent, 0);
        return appList;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * Install apk// w w w.ja  va2 s.  co  m
 */
public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:Main.java

public static String getCurLauncher(Context context) {
    if (context == null) {
        return null;
    }//ww  w . j  a  v a 2  s.co  m

    try {
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_HOME);
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(mainIntent, 0);
        if (resolveInfo != null) {
            return resolveInfo.activityInfo.packageName;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static final void gotoHome(Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addCategory(Intent.CATEGORY_HOME);
    context.startActivity(intent);//ww  w  . j  a  va  2  s  .c o m
}

From source file:Main.java

public static boolean backToHome(Context c) {
    Intent i = new Intent(Intent.ACTION_MAIN);

    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addCategory(Intent.CATEGORY_HOME);

    c.startActivity(i);/*from  w  w  w.jav  a 2s .com*/

    return true;
}