PhoneGap的3.3.0通下载的文件cdvfile网址媒体扫描 [英] Phonegap 3.3.0 pass downloaded file cdvfile url to Media Scanner
问题描述
我设法将文件下载到本地存储,但我不能设法传递所以它被添加到库中它的路径媒体扫描仪。
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;
}
的绝对路径参数是从JavaScript中file.toURL()。这是一个URL,如下所示。 cdvfile://localhost/persistent/Download/13republica_personal.jpg
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
我试图修改它/Download/13republica_personal.jpg,但它不能正常工作。
I tried to modify it to /Download/13republica_personal.jpg but it doesn't work.
我应该如何传递文件的URL /位置向媒体扫描仪使文件添加到库中?
How should I pass the file url/location to the media scanner so the file is added to the gallery?
推荐答案
结束了使用PhoneGap的插件文件的最后一个开发者版本,并使用文件对象作为媒体扫描仪的参数toLocalURL方法。
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.
这篇关于PhoneGap的3.3.0通下载的文件cdvfile网址媒体扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!