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

private static Intent getPdfFileIntent(File file) {
    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(file);/* w  ww .j  ava2  s .c o  m*/
    intent.setDataAndType(uri, "application/pdf");
    return intent;
}

From source file:Main.java

private static Intent getChmFileIntent(String filePath) {

    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(filePath));
    intent.setDataAndType(uri, "application/x-chm");
    return intent;
}

From source file:Main.java

private static Intent getPPTFileIntent(File file) {
    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(file);/* w  w  w  .j av a 2  s.c om*/
    intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    return intent;
}

From source file:Main.java

private static Intent getWordFileIntent(String filePath) {

    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(filePath));
    intent.setDataAndType(uri, "application/msword");
    return intent;
}

From source file:Main.java

private static Intent getWordFileIntent(File file) {
    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(file);//ww  w. j av a2  s .  c om
    intent.setDataAndType(uri, "application/msword");
    return intent;
}

From source file:Main.java

private static Intent getTextFileIntent(File file) {
    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(file);/*from   www .ja  v a 2s  . c  o  m*/
    intent.setDataAndType(uri, "text/plain");
    return intent;
}

From source file:Main.java

private static Intent getExcelFileIntent(String filePath) {

    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(filePath));
    intent.setDataAndType(uri, "application/vnd.ms-excel");
    return intent;
}

From source file:Main.java

public static boolean openAppActivity(Context context, String packageName, String activityName) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName cn = new ComponentName(packageName, activityName);
    intent.setComponent(cn);//  w  ww  .  j  a  v  a2s .  co m
    try {
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        return false;
    }
}

From source file:Main.java

private static Intent getImageFileIntent(String filePath) {

    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(filePath));
    intent.setDataAndType(uri, "image/*");
    return intent;
}

From source file:Main.java

public static List<ResolveInfo> loadApps(Context context) {
    List<ResolveInfo> mApps;
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    mApps = context.getPackageManager().queryIntentActivities(mainIntent, 0);
    return mApps;
}