我使用下面的代码来获取图像文件路径和缩略图.
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);}
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED);scanIntent.setData(Uri.fromfile(new file(Environment.getExternalStorageDirectory().getPath())));sendbroadcast(scanIntent);
但是,尽管文件数量更多,但花费的时间却更多.
所以我想确认下班后完成.
我怎么知道它完成了?
解决方法:
在下面运行:
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:
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;}}
总结 以上是内存溢出为你收集整理的android-我尝试扫描sdcard中的媒体文件并刷新全部内容,希望文章能够帮你解决android-我尝试扫描sdcard中的媒体文件并刷新所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)