List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:Main.java
/** Create a file Uri for saving an image or video */ @SuppressWarnings("unused") private static Uri getOutputMediaFileUri(int type) { return Uri.fromFile(getOutputMediaFile(type)); }
From source file:Main.java
public static void installApk(Context context, File file) { if (context == null) return;//from w w w.j a va 2 s . co m if (file == null) return; 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); }
From source file:Main.java
public static void install(Context context, String fileName) { if (TextUtils.isEmpty(fileName) || context == null) { return;/*from w w w .j a v a 2s . 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(); } }
From source file:Main.java
public static void notifyFileSystemChanged(String path, Context mContext) { if (path == null) return;/*from ww w . jav a 2 s .co m*/ final File f = new File(path); final Intent intent; if (f.isDirectory()) { intent = new Intent(Intent.ACTION_MEDIA_MOUNTED); intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver"); intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory())); } else { intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(new File(path))); } mContext.sendBroadcast(intent); }
From source file:Main.java
/** * install an apk bu apkPath/*from w ww. j a va 2s. c o m*/ * * @param context Context * @param apkPath apkPath */ public static final void installApk(Context context, String apkPath) { if (TextUtils.isEmpty(apkPath)) { return; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive"); context.startActivity(intent); }
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; }/*from w ww. ja v a2s .co m*/ } return false; }
From source file:Main.java
public static Bitmap getTempBitmap(Context context) { Bitmap capturedBitmap = null;/*from w w w. j av a2s .c om*/ final File file = getTempFile(context); try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; AssetFileDescriptor fileDescriptor = context.getContentResolver() .openAssetFileDescriptor(Uri.fromFile(file), "r"); capturedBitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options); } catch (Exception e) { e.printStackTrace(); } return capturedBitmap; }
From source file:Main.java
public static Uri createUri(String foldername) { String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { final File root = new File( Environment.getExternalStorageDirectory() + File.separator + foldername + File.separator); root.mkdirs();// ww w. j a va2 s. c om final String fname = getUniqueImageFilename(foldername); final File sdImageMainDirectory = new File(root, fname); return Uri.fromFile(sdImageMainDirectory); } return null; }
From source file:Main.java
public static void send(Context context, String path) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); PackageManager pm = context.getPackageManager(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); boolean flag = false; for (ResolveInfo info : list) { if (info.activityInfo.packageName.toLowerCase().contains("bluetooth") || info.activityInfo.name.toLowerCase().contains("bluetooth")) { ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { }//from w ww. j av a2 s .com if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0 && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); flag = true; break; } } } if (!flag) { return; } context.startActivity(intent); }
From source file:Main.java
private static void initData(Activity activity) { mActivity = activity;// ww w . ja v a 2 s. c o m File mFile = new File(Environment.getExternalStorageDirectory() + "/jiayuan"); if (!mFile.exists()) mFile.mkdirs(); mAvatar = new File(TEMP_IMG_PATH); if (mAvatar.exists()) mAvatar.delete(); mAvatarUri = Uri.fromFile(mAvatar); }