List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:Main.java
public static Intent getOpenFileIntent(File file) { if (file == null || !file.exists() || !file.isFile()) { return null; }/*www. ja v a 2 s. co m*/ 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; }
From source file:edu.stanford.mobisocial.dungbeetle.model.Feed.java
public static void view(Activity foreground, Uri feedUri) { Log.d("MMSSBB", "viewing " + feedUri); Intent launch = new Intent(Intent.ACTION_VIEW); launch.setDataAndType(feedUri, MIME_TYPE); foreground.startActivity(launch);// w w w . ja v a 2 s .c o m }
From source file:Main.java
public static Intent getAllIntent(String param) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File(param)); intent.setDataAndType(uri, "*/*"); return intent; }
From source file:Main.java
/** * install app//from ww w.jav a 2s. c o m * * @param context * @param filePath * @return whether apk exist */ public static boolean install(Context context, String filePath) { Intent i = new Intent(Intent.ACTION_VIEW); File file = new File(filePath); if (file != null && file.length() > 0 && file.exists() && file.isFile()) { i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive"); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); return true; } return false; }
From source file:Main.java
public static boolean installApp(Context context, String filePath) { if (filePath != null && filePath.length() > 4 && filePath.toLowerCase().substring(filePath.length() - 4).equals(".apk")) { Intent intent = new Intent(Intent.ACTION_VIEW); File file = new File(filePath); if (file.exists() && file.isFile() && file.length() > 0) { intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; }//ww w.j a v a 2s . c o m } return false; }
From source file:Main.java
public static Intent showOpenTypeDialog(String param) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File(param)); intent.setDataAndType(uri, "*/*"); return intent; }
From source file:Main.java
public static void install(Context context, String apkFilePath) { if (context == null) { throw new RuntimeException("ApkUtils install apk method and parameter context == null?"); }//from w w w .j a va 2 s .c o m File file = new File(apkFilePath); if (!file.exists()) { return; } Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(intent); }
From source file:Main.java
public static Intent getApkFileIntent(String param) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File(param)); intent.setDataAndType(uri, "application/vnd.android.package-archive"); return intent; }
From source file:Main.java
private static Intent getAllIntent(String filePath) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File(filePath)); intent.setDataAndType(uri, "*/*"); return intent; }
From source file:Main.java
public static void install(Context context, String fileName) { if (TextUtils.isEmpty(fileName) || context == null) { return;// ww w . j a va 2 s . c om } try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }