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 List<ResolveInfo> getShareTargets(Context ctx) {
    Intent intent = new Intent(Intent.ACTION_SEND, null);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("text/plain");
    PackageManager pm = ctx.getPackageManager();
    return pm.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
}

From source file:Main.java

public static void startLauncher(Context context) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    context.startActivity(intent);/*from w ww. ja v  a  2s  .c om*/
}

From source file:Main.java

public static void link(Context context, String url) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setData(Uri.parse(url));//from w  ww  . java  2s . c  o m
    context.startActivity(intent);
}

From source file:Main.java

public static void openImage(Context mContext, String imagePath) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(imagePath));
    intent.setDataAndType(uri, "image/*");
    mContext.startActivity(intent);/*from  w w w.j  a  v a2 s . co  m*/
}

From source file:Main.java

public static Intent getWordFileIntent(String param) {

    Intent intent = new Intent("android.intent.action.VIEW");

    intent.addCategory("android.intent.category.DEFAULT");

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    Uri uri = Uri.fromFile(new File(param));

    intent.setDataAndType(uri, "application/msword");

    return intent;

}

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
 *//*from  ww  w  .  j a v a 2 s .c o  m*/
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

static void showDesktop(Context ctx) {
    Intent mHomeIntent;
    mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    ctx.startActivity(mHomeIntent);//  www  .java 2  s .  c o  m
}

From source file:Main.java

public static void startShareIntentActivity(Activity activity, String text) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    activity.startActivity(intent);/*from   w w  w.jav  a  2s . c  o  m*/
}

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  ww  w . jav  a 2s. c om
//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;
    }
}

From source file:Main.java

private 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 w w . j av  a  2s.  com*/
    }
    return null;
}