简体   繁体   English

Android - Java - MEDIA_SCANNER_SCAN_FILE

[英]Android - Java - MEDIA_SCANNER_SCAN_FILE

I am working with Phonegap / Cordova 3.3 in Android and am trying to create a native plugin using Java. 我在Android中使用Phonegap / Cordova 3.3并尝试使用Java创建本机插件。 The function I am trying to call is the MEDIA_SCANNER_SCAN_FILE. 我试图调用的函数是MEDIA_SCANNER_SCAN_FILE。 Here is my code. 这是我的代码。

...

File file = new File(filePath);

Uri contentUri = Uri.fromFile(file);
Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
mediaScanIntent.setData(contentUri);

this.cordova.getActivity().sendBroadcast(mediaScanIntent);

...

The code seems to execute fine. 代码似乎执行得很好。 However, the file does not get added to the media library. 但是,该文件不会添加到媒体库中。 I am passing the full path name to the function. 我将完整的路径名传递给函数。

Any thoughts? 有什么想法吗?

Thanks 谢谢

Did you hardcode the filePath? 你是否对filePath进行了硬编码?
Take a look at this post http://androidyue.github.io/blog/2014/01/19/scan-media-files-in-android/ It's expressed in detail. 看一下这篇文章http://androidyue.github.io/blog/2014/01/19/scan-media-files-in-android/它的详细说明。 I hope this could help you. 我希望这可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM