本文介绍了刷新图像的媒体库影片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根据需要移动和删除了大量图像和视频,现在我正在使用以下介质扫描媒体
I moving and deleting lots of images and videos as per my requirement and now i am scan media by using
Intent scanFileIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
sendBroadcast(scanFileIntent);
一切正常,但有时会冻结屏幕,我认为MediaScanner中存在一些问题。
all working fine but sometime freeze the screen, i think some issue in MediaScanner.
我的第二个问题是如何扫描所有媒体存储介质而不是扫描perticuler文件。
And my second quetion is how to scan all media Store rether than scan perticuler File.
谢谢!!! >
Thanks in Advance!!
推荐答案
您应尝试使用此解决方案删除并删除图像。
You should try this solution for amove and delete the image.
在deleteRecursive(fileOrDirectory)内部传递文件目录路径,即可从文件或目录中删除多个图像和单个图像。
public void deleteRecursive(File fileOrDirectory) {
if (!fileOrDirectory.isDirectory()) return;
File[] childFiles = fileOrDirectory.listFiles();
if (childFiles == null) return;
if (childFiles.length == 0) {
fileOrDirectory.delete();
} else {
for (File childFile : childFiles) {
deleteRecursive(childFile);
DeleteAndScanFile(MainActivity.this, childFile.getPath(), childFile);
}
}
}
private void DeleteAndScanFile(final Context context, String path,
final File fi) {
String fpath = path.substring(path.lastIndexOf("/") + 1);
try {
MediaScannerConnection.scanFile(context, new String[]{Environment
.getExternalStorageDirectory().toString()
+ "/abc/"
+ fpath.toString()}, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
if (uri != null) {
context.getContentResolver().delete(uri, null,
null);
}
fi.delete();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
对我来说这是好工作,希望这可以帮助您...如果您需要任何帮助,可以询问
It's Good work for me, Hope this help you...if you need any help you can ask
这篇关于刷新图像的媒体库影片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!