List of usage examples for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE
String ACTION_MEDIA_SCANNER_SCAN_FILE
To view the source code for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE.
Click Source Link
From source file:Main.java
/** * Helper method for adding the photo to the system photo gallery so it can be accessed * from other apps.//from w w w .ja v a 2 s .co m * * @param imagePath The path of the saved image */ private static void galleryAddPic(Context context, String imagePath) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(imagePath); Uri contentUri = Uri.fromFile(f); mediaScanIntent.setData(contentUri); context.sendBroadcast(mediaScanIntent); }
From source file:Main.java
private static void scanPhoto(Context ctx, String imgFileName) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File file = new File(imgFileName); Uri contentUri = Uri.fromFile(file); mediaScanIntent.setData(contentUri); ctx.sendBroadcast(mediaScanIntent);/*from ww w. j a v a 2 s . co m*/ }
From source file:Main.java
private static void addTomMediaScanner(Context context, Uri uri) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(uri);/*from w w w . j a va 2 s .com*/ context.sendBroadcast(mediaScanIntent); }
From source file:Main.java
/** * Save an image URI into the gallery/*w w w.j a va 2s . co m*/ * @param context the context. * @param sourceFile the image path to save. */ public static String saveImageIntoGallery(Context context, File sourceFile) { String filePath = saveFileInto(context, sourceFile, Environment.DIRECTORY_PICTURES, null); if (null != filePath) { // This broadcasts that there's been a change in the media directory context.sendBroadcast( new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(filePath)))); } return filePath; }
From source file:Main.java
public static void scanFile(String path, Context c) { System.out.println(path + " " + Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT >= 19) { MediaScannerConnection.scanFile(c, new String[] { path }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override//from ww w . ja v a 2 s . c o m public void onScanCompleted(String path, Uri uri) { } }); } else { Uri contentUri = Uri.fromFile(new File(path)); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri); c.sendBroadcast(mediaScanIntent); } }
From source file:Main.java
public static Bitmap saveBitmapToFile(Activity activity, Bitmap bitmap) { String mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); File imageFile = new File(mPath); boolean create = imageFile.mkdirs(); boolean canWrite = imageFile.canWrite(); Calendar cal = Calendar.getInstance(); String date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE); String filename = null;/* ww w. jav a 2s.c o m*/ int i = 0; while (imageFile.exists()) { i++; filename = date + "_mandelbrot" + i + ".png"; imageFile = new File(mPath, filename); boolean canWrite2 = imageFile.canWrite(); } try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); /*resultB*/bitmap.compress(CompressFormat.PNG, 90, bos); byte[] bitmapdata = bos.toByteArray(); //write the bytes in file FileOutputStream fos = new FileOutputStream(imageFile); fos.write(bitmapdata); fos.flush(); fos.close(); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(imageFile)); activity.sendBroadcast(intent); displaySuccesToast(activity); } catch (FileNotFoundException e) { displayFileError(activity); e.printStackTrace(); } catch (IOException e) { displayFileError(activity); e.printStackTrace(); } return bitmap; }
From source file:br.com.brunogrossi.MediaScannerPlugin.MediaScannerPlugin.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {//from w w w . j a v a2s .com if (action.equals("scanFile")) { String fileUri = args.optString(0); if (fileUri != null && !fileUri.equals("")) { Uri contentUri = Uri.parse(fileUri); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(contentUri); this.cordova.getActivity().sendBroadcast(mediaScanIntent); callbackContext.success(); return true; } else { Log.w(TAG, "No action param provided: " + action); callbackContext.error("No action param provided: " + action); return false; } } else { Log.w(TAG, "Wrong action was provided: " + action); return false; } } catch (RuntimeException e) { e.printStackTrace(); callbackContext.error(e.getMessage()); return false; } }
From source file:com.guinatal.refreshgallery.PluginRefreshGallery.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//* w w w . j av a 2s.c o m*/ @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { this.callbackContext = callbackContext; try { if (action.equals("refresh")) { String filePath = checkFilePath(args.getString(0)); if (filePath.equals("")) { PluginResult r = new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(r); return true; } File file = new File(filePath); Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(file)); Context context = webView.getContext(); context.sendBroadcast(scanIntent); } PluginResult r = new PluginResult(PluginResult.Status.OK); callbackContext.sendPluginResult(r); return true; } catch (JSONException e) { PluginResult r = new PluginResult(PluginResult.Status.JSON_EXCEPTION); callbackContext.sendPluginResult(r); return true; } catch (Exception e) { PluginResult r = new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(r); return true; } }
From source file:com.kircherelectronics.gyroscopeexplorer.datalogger.CsvDataLogger.java
public String writeToFile() { try {/*from w w w.j a va 2 s.co m*/ fileWriter.flush(); fileWriter.close(); csv.close(); } catch (IOException e) { e.printStackTrace(); } context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); return file.getPath(); }
From source file:com.darktalker.cordova.screenshot.Screenshot.java
private void scanPhoto(String imageFileName) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(imageFileName); Uri contentUri = Uri.fromFile(f);/* ww w . j a v a2 s. c o m*/ mediaScanIntent.setData(contentUri); this.cordova.getActivity().sendBroadcast(mediaScanIntent); }