List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:Main.java
/** * Install a given file via package installer * //w w w . j a v a 2 s.com * @param context * @param file */ public static void installFile(Context context, File file) { if (file != null) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(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 w w . jav a 2 s. c om }
From source file:Main.java
public static void addImageToDeviceGallery(final Context context, final String imagePath) { final Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE"); final File f = new File(imagePath); final Uri contentUri = Uri.fromFile(f); mediaScanIntent.setData(contentUri); context.sendBroadcast(mediaScanIntent); }
From source file:Main.java
public static void openFile(File aFile, Context context) { Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW); File file = new File(aFile.getAbsolutePath()); String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString()); String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); myIntent.setDataAndType(Uri.fromFile(file), mimetype); context.startActivity(myIntent);// w w w . j av a2 s. c om }
From source file:Main.java
public static void installApk(Context context, File file) { Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.setType("application/vnd.android.package-archive"); intent.setData(Uri.fromFile(file)); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);/*from w w w .j a v a2 s.c o m*/ }
From source file:Main.java
/** * Install apk// w ww . j a v a 2s . co m */ public static void installApk(Context context, File file) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
From source file:Main.java
public static void takePicture(Activity mActivity, String imagePath) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (null != imagePath && !imagePath.isEmpty()) { intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(imagePath))); }/* ww w . ja v a 2 s. co m*/ mActivity.startActivityForResult(intent, BBS_REQUEST_CAMERA); }
From source file:Main.java
/** * Add file photo to gallery after capture from camera or downloaded. * * @param context//from w w w. ja v a 2 s. c o m * @param file */ public static void galleryAddPic(Context context, File file) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(file); mediaScanIntent.setData(contentUri); context.sendBroadcast(mediaScanIntent); }
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);// ww w.j a v a2 s. c om return intent; }
From source file:Main.java
/** * Create a file Uri for saving an image or video */// w w w . j a v a 2 s . co m public static Uri getOutputMediaFileUri(int type) { return Uri.fromFile(getOutputMediaFile(type)); }