Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Got to create a plugin from it , here it is </p> <p>the scanMedia.java</p> <pre><code>public class scanMedia extends CordovaPlugin { @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (!action.equals("mediaScanner")) { return false; } try { String absolutePath = args.getString(0); if (absolutePath.startsWith("data:image")) { absolutePath = absolutePath.substring(absolutePath.indexOf(',') + 1); } return this.mediaScanner(absolutePath, 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 mediaScanner(String absolutePath, CallbackContext callbackContext) throws InterruptedException, JSONException { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); //File f = new File(filename); Uri contentUri = Uri.parse(absolutePath.toString()); mediaScanIntent.setData(contentUri); System.out.println("from internal?" + contentUri); //this.cordova.getContext().sendBroadcast(mediaScanIntent); //this is deprecated this.cordova.getActivity().sendBroadcast(mediaScanIntent); return true; } } </code></pre> <p>the scanMedia.js</p> <pre><code>(function() { /* This increases plugin compatibility */ var cordovaRef = window.PhoneGap || window.Cordova || window.cordova; // old to new fallbacks /** * The Java to JavaScript Gateway 'magic' class */ function scanMedia(){ } scanMedia.prototype.mediaScanner = function(string, win, fail) { cordovaRef.exec(win, fail, "scanMedia", "mediaScanner", [string]); }; cordovaRef.addConstructor(function() { if (!window.plugins) { window.plugins = {}; } if (!window.plugins.scanMedia) { window.plugins.scanMedia = new scanMedia(); } }); })(); </code></pre> <p>and reference in the config.xml file</p> <pre><code>&lt;plugin name="scanMedia" value="org.apache.cordova.scanMedia"/&gt; </code></pre> <p>In order to call the plugin you need to pass the file.fullPath to the function (<a href="http://docs.phonegap.com/en/2.5.0/cordova_file_file.md.html#FileReader" rel="nofollow">you use the phonegap file reader</a>)</p> <pre><code>var theLink = fileEntry.fullPath; window.plugins.scanMedia.mediaScanner(theLink, function(result) { console.log(result); }, function(error) { console.log(error); }); </code></pre> <p>Hope it helps somebody in need of media discovery. If anybody can do this for iOS that would be great :)</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.
 

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