List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:Main.java
/** * Convert File into Uri.//from w w w.j a v a 2 s.c om * * @param file * @return uri */ public static Uri getUri(File file) { if (file != null) { return Uri.fromFile(file); } return null; }
From source file:Main.java
/** * Creates a temporary file for storing a photo that will be taken with the * camera.// w w w.ja v a 2 s. c om * * @param context * the application's context * @return a Uri that points to the file */ public static Uri getPhotoUri(Context context) { File photo; try { // place where to store camera taken picture photo = createTemporaryFile("picture", ".jpg", context); photo.delete(); } catch (Exception e) { Log.v(TAG, "Can't create file to take picture!"); return null; } Uri mImageUri = Uri.fromFile(photo); return mImageUri; }
From source file:Main.java
public static Uri getOutputMediaFileUri() { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Date"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("Date", "failed to create directory"); return null; }// w ww. j av a 2s . co m } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); return Uri.fromFile(mediaFile); }
From source file:Main.java
public static void installApk(Context context, String apkPath) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);/* w ww. ja va2s . c o m*/ }
From source file:Main.java
private static String toDirUrl(File f) { return Uri.fromFile(f).toString() + '/'; }
From source file:Main.java
public static void installApkWithPrompt(File apkFile, Context context) { Intent promptInstall = new Intent(Intent.ACTION_VIEW); promptInstall.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); context.startActivity(promptInstall); }
From source file:Main.java
public static Uri saveBitmapToSDCard(Bitmap bitmap, String title) { File appDir = new File(Environment.getExternalStorageDirectory(), "Gank"); if (!appDir.exists()) { appDir.mkdirs();//w w w . j a va 2 s. c o m } String fileName = title.replace("/", "-") + "-girl.jpg"; File file = new File(appDir, fileName); FileOutputStream outputStream; try { outputStream = new FileOutputStream(file); assert bitmap != null; bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); outputStream.flush(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); return null; } return Uri.fromFile(file); }
From source file:Main.java
public static void install(Context context, File file) { try {/*from w w w. j a va 2s . c o m*/ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void startCamera(Activity activity, int requestCode, File outPath) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.fromFile(outPath); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); activity.startActivityForResult(intent, requestCode); }
From source file:Main.java
public static void installApk(Context context, 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"); context.startActivity(intent);/* ww w . j av a 2 s .com*/ }