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 boolean installApk(Context context, String archiveFilePath) { try {/*w w w .jav a2 s . c om*/ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse("file:///" + archiveFilePath), "application/vnd.android.package-archive"); context.startActivity(intent); return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static void installApk(Context context, File file) { Intent intent = new Intent(); intent.addFlags(268435456);//from ww w . j a v a 2 s . c om intent.setAction("android.intent.action.VIEW"); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(intent); }
From source file:com.google.android.demos.jamendo.widget.TrackListAdapter.java
public static void playTrack(Activity activity, long trackId) { Uri data = JamendoContract.createTrackUri(trackId, JamendoContract.STREAM_ENCODING_MP3); String type = JamendoContract.CONTENT_TYPE_MP3; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(data, type); new RedirectHandler(activity).execute(intent); }
From source file:Main.java
public static void installApk(Context context, String path) { File file = new File(path); if (file.exists()) { Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); installIntent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(installIntent); }//from w ww .j ava 2 s. c o m }
From source file:Main.java
public static Intent getInstallApkIntent(File file) { Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); return intent; }
From source file:Main.java
public static void installApk(Context context, Uri file) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(file, "application/vnd.android.package-archive"); context.startActivity(intent);/* w w w . ja va 2 s . c om*/ }
From source file:Main.java
public static Intent getInstallIntent(File file) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); return intent; }
From source file:com.github.fi3te.iliasdownloader.controller.Util.java
public static void openFile(File file, Activity forMessages) { if (file != null && forMessages != null && file.isFile()) { String extension = FilenameUtils.getExtension(file.getPath()); if (extension.length() > 0) { try { extension = extension.toLowerCase(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); forMessages.startActivity(intent); } catch (ActivityNotFoundException anfe) { Toast.makeText(forMessages, forMessages.getResources().getString(R.string.unknown_type), Toast.LENGTH_SHORT).show(); }//from w w w .j a v a2s . co m } } }
From source file:Main.java
/** * Show a level//from w ww. j ava 2 s . c o m * * @param context The context * @param level The level */ public static void showLevel(Context context, int level) { String filename; switch (level) { case 1: { filename = "ground_floor.png"; break; } case 2: { filename = "talks_floor.png"; break; } default: { return; } } File f = new File(context.getFilesDir() + "/" + filename); try { if (f.exists() == false) { InputStream is = context.getAssets().open(filename); FileOutputStream fos = context.openFileOutput(filename, Context.MODE_WORLD_READABLE); byte[] buffer = new byte[is.available()]; is.read(buffer); // write the stream to file fos.write(buffer, 0, buffer.length); fos.close(); is.close(); } // Prepare the intent //TODO - create an activity for this instead. Internal viewers might be quite heavy Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(f), "image/png"); context.startActivity(intent); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void installAPK(Context context, File file) { if (file == null || !file.exists()) return;//from w w w . ja v a 2s. com Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(intent); }