我正在寻找可以扫描特定文件夹中文件的媒体扫描源。
或扫描特定文件夹中特定扩展文件(如 .mp4)的源。
谢谢。
问问题
6339 次
2 回答
4
我正在寻找可以在特定文件夹中找到文件的媒体扫描源
MediaScannerConnection.scanFile将第二个参数作为要扫描的路径的字符串数组
扫描特定文件夹中特定扩展文件(如 .mp4)的源。
MediaScannerConnection.scanFile将第三个参数作为mimeTypes
我们要扫描的字符串数组。
例子:
String[] paths = {path_to_scan};
String[] mimeTypes = {"video/mp4"};
MediaScannerConnection.scanFile(getApplicationContext(),
paths,
mimeTypes,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
// scanned path and uri
}
});
于 2015-02-25T04:52:06.873 回答
3
使用以下代码从特定文件夹中获取文件:
File folder_file = new File("give specific folder path");
File[] files = folder_file.listFiles();
if (files != null) {
for (File file : files) {
// checking the File is file or directory
if (file.isFile()) {
String path = file.getAbsolutePath();
String extension = path
.substring(path.lastIndexOf(".") + 1);
// if the file is audio type, then save it to the database
if (extension.equalsIgnoreCase("mp4")) {
System.out.println(path + " is a media file ");
}
}
}
}
试试这个扫描文件:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
.parse("file://"
+ Environment.getExternalStorageDirectory())));
于 2015-02-25T04:51:18.760 回答