mediastore查询指定目录里面的文件

//设定查询目录,查询指定目录里面的图片
// String path= "%"+ Environment.getExternalStorageDirectory()+ File.separator+"Pictures"+File.separator+"快轮智能";
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/Pictures";

//selection: 指定查询条件
String selection = MediaStore.Images.Media.DATA + " like ?";
//设定查询目录,
//定义selectionArgs:
String[] selectionArgs = {path + "%"};
// Cursor mCursor = mContext.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null,
//// selection, selectionArgs, null);
//查看指定文件夹里面的所有文件
Cursor mCursor = mContext.getContentResolver().query(MediaStore.Files.getContentUri( "external" ) ,null,
selection, selectionArgs, null);

            Log.e("gyx", mCursor.getCount() + "");

            //利用Handler通知调用线程
            Message msg = mHandler.obtainMessage();

            msg.obj = mCursor;



            mHandler.sendMessage(msg);

你可能感兴趣的:(mediastore查询指定目录里面的文件)