【发布时间】:2014-05-12 03:54:02
【问题描述】:
我设法将文件下载到本地存储,但我无法将它的路径传递给媒体扫描仪,因此它被添加到图库中。
我添加了一个用于媒体扫描仪工作的插件。 试图做到这一点的函数就是这个。
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()。这是一个看起来像这样的网址。 cdvfile://localhost/persistent/Download/13republica_personal.jpg
我尝试将其修改为 /Download/13republica_personal.jpg 但不起作用。
我应该如何将文件 url/位置传递给媒体扫描器,以便将文件添加到库中?
【问题讨论】:
-
你在哪里找到那个插件的?
-
这里是link
标签: android file cordova download android-mediascanner