试试这个,应该好使 // Tell the media scanner about the new file so that it is // immediately available to the user. MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { Log.i("ExternalStorage", "Scanned " + path + ":"); Log.i("ExternalStorage", "-> uri=" + uri); } }); 祝你成功!
Uri data = Uri.parse("file://" +"这里是图片路径"); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
祝你成功!
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
String file= Environment.getExternalStorageDirectory().getAbsolutePath()+"/Photo";
folderScan(file);
}
private void fileScan(String file){
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
}
private void folderScan(String path){
File file = new File(path);
if(file.exists() && 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.endsWith(".mp4") || name.endsWith(".mp3") || name.endsWith(".jpg")){
fileScan(f.getAbsolutePath());
}
}
else {//FOLDER TYPE
folderScan(f.getAbsolutePath());
}
}
}
}