通过自己发送广播,mediascanner接收到广播会启动扫描资源库的服务,从而刷新资源库
-扫描全部
- public
void systemScan(){ -
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" -
+ Environment.getExternalStorageDirect ory()))); -
}
-
- public
void fileScan(String file){ -
Uri data = Uri.parse("file://"+file); -
-
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data)); -
}
- 扫描文件夹 参数:填入该文件夹路径
- public
void fileScan(String file){ -
Uri data = Uri.parse("file://"+file); -
-
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data)); -
} -
-
public void folderScan(String path){ -
File file = new File(path); -
-
if(file.isDirectory()){ -
File[] array = file.listFiles(); -
-
for(int i=0;i<array.length;i++){ -
File f = array[i]; -
-
if(f.isFile()){//FILE TYPE -
String name = f.getName(); -
-
if(name.contains(".mp3")){ -
fileScan(f.getAbsolutePath()); -
} -
} -
else {//FOLDER TYPE -
folderScan(f.getAbsolutePath()); -
} -
} -
} -
}