List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:Main.java
public static Intent getPptFileIntent(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/vnd.ms-powerpoint"); return intent; }
From source file:Main.java
public static Intent getChmFileIntent(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/x-chm"); return intent; }
From source file:Main.java
public static List<ResolveInfo> getInstalledAppsByActionMainIntent(Context context) { final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); return context.getPackageManager().queryIntentActivities(mainIntent, 0); }
From source file:Main.java
private static void prepareRestartAppIntent(Intent i) { i.setAction(Intent.ACTION_MAIN);//www .ja v a2 s . c om i.addCategory(Intent.CATEGORY_LAUNCHER); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }
From source file:Main.java
public static ResolveInfo getResolveInfo(PackageManager pm, String packageName) { Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(packageName);// w w w . j a va 2 s . co m List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); if (apps != null && apps.size() > 0) { return apps.get(0); } return null; }
From source file:Main.java
private static Intent getIntentByType(String param, String type) { 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, type);// w w w. j ava 2 s.c o m return intent; }
From source file:Main.java
public static void addHome(Context context) { Intent homeIntent = new Intent("android.intent.action.MAIN"); homeIntent.addCategory("android.intent.category.HOME"); homeIntent.addCategory("android.intent.category.DEFAULT"); Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, homeIntent); context.startActivity(chooserIntent); }
From source file:Main.java
public static void openPDF(Context context, String path) { 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(path)); intent.setDataAndType(uri, "application/pdf"); try {/*from w ww . j av a 2 s.co m*/ context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static String getLActivityName(Context context) { Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> resolvInfos = context.getPackageManager().queryIntentActivities(intent, 0); String launcherActivityName = ""; for (int i = 0; i < resolvInfos.size(); i++) { launcherActivityName = resolvInfos.get(i).activityInfo.name; }//from ww w . ja v a 2s . c o m return launcherActivityName; }
From source file:Main.java
public static Intent getOpenFileIntent(File file) { if (file == null || !file.exists() || !file.isFile()) { return null; }/*from w w w. java 2 s .com*/ String extension = MimeTypeMap.getFileExtensionFromUrl(file.getAbsolutePath()); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (extension == null || mimeType == null) { return null; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(file), mimeType); return intent; }