Note that there are some explanatory texts on larger screens.

plurals
  1. POPhonegap - How to trigger media scanner after creating file
    primarykey
    data
    text
    <p>I have the following code (this is a plugin to save a base64 as an image file on the phone) </p> <pre><code> @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (!action.equals("saveImage")) { return false; } try { String b64String = args.getString(0); if (b64String.startsWith("data:image")) { b64String = b64String.substring(b64String.indexOf(',') + 1); } JSONObject params = args.getJSONObject(1); //Optional parameter String filename = params.has("filename") ? params.getString("filename") : "drawsaur_" + System.currentTimeMillis() + ".png"; String folder = params.has("folder") ? params.getString("folder") : Environment.getExternalStorageDirectory() + "/drawsaur"; Boolean overwrite = params.has("overwrite") ? params.getBoolean("overwrite") : false; return this.saveImage(b64String, filename, folder, overwrite, callbackContext); } catch (JSONException e) { e.printStackTrace(); callbackContext.error(e.getMessage()); return false; } catch (InterruptedException e) { e.printStackTrace(); callbackContext.error(e.getMessage()); return false; } } private boolean saveImage(String b64String, String fileName, String dirName, Boolean overwrite, CallbackContext callbackContext) throws InterruptedException, JSONException { try { //Directory and File File dir = new File(dirName); if (!dir.exists()) { dir.mkdirs(); } File file = new File(dirName, fileName); //Avoid overwriting a file if (!overwrite &amp;&amp; file.exists()) { callbackContext.error("File already exists!"); return true; } //Decode Base64 back to Binary format byte[] decodedBytes = Base64.decode(b64String.getBytes()); //Save Binary file to phone file.createNewFile(); FileOutputStream fOut = new FileOutputStream(file); fOut.write(decodedBytes); fOut.close(); callbackContext.success("Saved successfully to " + dirName + "/" + fileName); return true; } catch (FileNotFoundException e) { callbackContext.error("File not Found!"); return false; } catch (IOException e) { callbackContext.error(e.getMessage()); return false; } } </code></pre> <p>I need to trigger media scan on the file so android will show the file in gallery. How can I do this ? I am using Phonegap 2.9.0 and testing on nexus4</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload