Phonegap 3.3.0 pass downloaded file cdvfile url to Media Scanner

两盒软妹~` 提交于 2019-12-24 12:11:03

问题


I managed to download a file to the local storage but I can't manage to pass it's path to the media scanner so it gets added to the gallery.

I've added a plugin that does the media scanner work. The function that tries to do the trick is this one.

private boolean mediaScanner(String absolutePath, CallbackContext callbackContext)  throws InterruptedException, JSONException
{
      Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
      String path = Uri.parse(absolutePath).getPath();
      File f = new File(path.substring(path.indexOf('/', 1)));
      mediaScanIntent.setData(Uri.fromFile(f));
      this.cordova.getActivity().sendBroadcast(mediaScanIntent);
      return true;
}

The absolute path parameter is the file.toURL() from the javascript. It's an url that looks like this. cdvfile://localhost/persistent/Download/13republica_personal.jpg

I tried to modify it to /Download/13republica_personal.jpg but it doesn't work.

How should I pass the file url/location to the media scanner so the file is added to the gallery?


回答1:


Ended up using the last developer version of phonegap file plugin and using toLocalURL method of the file object as parameter of the media scanner.



来源:https://stackoverflow.com/questions/22784791/phonegap-3-3-0-pass-downloaded-file-cdvfile-url-to-media-scanner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!