Example usage for android.content Intent CATEGORY_LAUNCHER

List of usage examples for android.content Intent CATEGORY_LAUNCHER

Introduction

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

Prototype

String CATEGORY_LAUNCHER

To view the source code for android.content Intent CATEGORY_LAUNCHER.

Click Source Link

Document

Should be displayed in the top-level launcher.

Usage

From source file:Main.java

public static String getAppMainActivity(Context context, String packageName) {
    if (TextUtils.isEmpty(packageName)) {
        return "";
    }/*from   w  w  w.  j a  v  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

/**
 * @param packageName//w w w  . ja v a2s. c  o  m
 * @param context
 */
public static void openApp(String packageName, Context context) {

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);

    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    resolveIntent.setPackage(packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo ri = apps.iterator().next();

    if (ri != null) {

        String packageName_i = ri.activityInfo.packageName;

        String className_i = ri.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        ComponentName cn = new ComponentName(packageName_i, className_i);

        intent.setComponent(cn);

        context.startActivity(intent);

    }

}

From source file:Main.java

public static void startApkActivity(final Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    PackageInfo pi;/*from ww w.  j a v  a2 s . c om*/
    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();
    }
}

From source file:Main.java

/**
 * <pre>/*from w  w w .  j a  v  a2  s  . com*/
 * Start other app by its package name.
 * </pre>
 * @param packageName app 's package name
 */
public static void openApp(String packageName) {
    Context context = getCurrentContext();
    PackageManager manager = context.getPackageManager();
    Intent intent = manager.getLaunchIntentForPackage(packageName);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    context.startActivity(intent);
}

From source file:Main.java

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

From source file:Main.java

/**
 * Checks the availability of the DownloadManager.
 *
 * @param context used to update the device version and DownloadManager information
 * @return true if the download manager is available
 *///ww  w.  ja  v a2 s .  c om
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.isEmpty();
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static void startAppByPackageName(Context context, String packageName) {
    PackageInfo pi = null;// w  ww  .jav  a 2  s  .c  o m
    try {
        pi = context.getPackageManager().getPackageInfo(packageName, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(pi.packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo ri = apps.iterator().next();
    if (ri != null) {
        String packageName1 = ri.activityInfo.packageName;
        String className = ri.activityInfo.name;

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

        ComponentName cn = new ComponentName(packageName1, className);

        intent.setComponent(cn);
        context.startActivity(intent);
    }

}

From source file:Main.java

private static void prepareRestartAppIntent(Intent i) {
    i.setAction(Intent.ACTION_MAIN);//from  ww  w. ja  v a 2  s .c o  m
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

/**
 * open another app//  ww  w . j  a v a2  s.c om
 * @param context
 * @param packageName
 * @throws NameNotFoundException 
 */
public static void openApp(Context context, String packageName) throws NameNotFoundException {
    PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, 0);

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(pi.packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    Iterator<ResolveInfo> iterator = apps.iterator();
    while (iterator.hasNext()) {
        ResolveInfo ri = iterator.next();
        if (ri != null) {
            packageName = ri.activityInfo.packageName;
            String className = ri.activityInfo.name;
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            ComponentName cn = new ComponentName(packageName, className);
            intent.setComponent(cn);
            context.startActivity(intent);
        }
    }
}

From source file:Main.java

/**
 * @param context used to check the device version and DownloadManager information
 * @return true if the download manager is available
 *///from   w  w w  .  j a v a 2 s. c  o  m
//http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog
public static boolean isDownloadManagerAvailable() {
    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 = m_TempContext.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    } catch (Exception e) {
        return false;
    }
}