我尝试扫描媒体文件的SD卡,并刷新 [英] I try scan media file in sdcard and refresh it

查看:171
本文介绍了我尝试扫描媒体文件的SD卡,并刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用低于code得到的图像文件的路径和它的缩略图。

I use below code to get image file path and it thumbnail.

String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.DATA};  
Cursor cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Media._ID); 
int count = cursor.getCount();
int image_column_index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
int image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
int i;
for(i = 0; i < count; i++) {
cursor.moveToPosition(i);
int id = cursor.getInt(image_column_index);
String p = cursor.getString(image_path_index);
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
}

和我下面code尝试刷新数据库文件进行修改后。

And I try below code to refresh the database after file be modified.

Intent scanIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
scanIntent.setData(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath())));
sendBroadcast(scanIntent);

不过,虽然文件编号多了,花费的时间更多。 所以我想确认工作完成后向。 我该怎么做才能知道它完成?

But while the file number more, it spend time more. So I want to confirm it finish to after work. How can I do to know it finish?

推荐答案

以下运行:

IntentFilter intentfilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentfilter.addDataScheme("file");
MediaScannerReceiver scanSdReceiver = new MediaScannerReceiver();
scanSdReceiver.setRestart(false);
egisterReceiver(scanSdReceiver, intentfilter);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath()))); 

和定义类MediaScannerReceiver:

And define class MediaScannerReceiver:

public class MediaScannerReceiver extends BroadcastReceiver {  
private boolean restart = false;
@Override  
public void onReceive(Context context, Intent intent) {  
String action = intent.getAction();
if(action.equals("android.intent.action.MEDIA_SCANNER_FINISHED")) {  
//update finish
} 
}  
public void setRestart(boolean r) {
this.restart = r;
}
}  

这篇关于我尝试扫描媒体文件的SD卡,并刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆