Android 在MediaStore managedQuery中指定文件夹
您好,我想在SD卡上指定一个文件夹,以检索该文件夹(例如,/mnt/sdcard/folder/subfolder)子文件夹中的所有图像。我有这个:Android 在MediaStore managedQuery中指定文件夹,android,sd-card,mediastore,Android,Sd Card,Mediastore,您好,我想在SD卡上指定一个文件夹,以检索该文件夹(例如,/mnt/sdcard/folder/subfolder)子文件夹中的所有图像。我有这个: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery); GridView gridview = (GridView) findViewById
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
GridView gridview = (GridView) findViewById(R.id.gallery);
registerForContextMenu(gridview);
id = getIntent().getExtras().getString("ID");
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Thumbnails._ID};
// Create the cursor pointing to the SDCard
cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
MediaStore.Images.Thumbnails.IMAGE_ID);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
在gridview的setAdapter中,我有:
gridview.setAdapter(new BaseAdapter() {
public View getView(int position, View convertView, ViewGroup parent) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(mContext);
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image based on the provided URI
picturesView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
picturesView.setLayoutParams(new GridView.LayoutParams(100, 100));
}
else {
picturesView = (ImageView)convertView;
}
return picturesView;
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
});
这是工作,但给我看SD卡中包含的所有图像。。。
我尝试设置URI路径,如“content:///mnt/sdcard/folder/subfolder“但它不起作用……如何在MediaStore managedQuery中指定要扫描的特定文件夹?”
提前谢谢大家!:) 尝试获取字段-它包含图像文件的完整路径。然后,您可以通过光标运行并仅选择您感兴趣的文件,或者构建查询,使其仅返回路径为“LIKE%your\u folder\u name%”的条目。尝试获取字段-它包含图像文件的完整路径。然后,您可以运行光标,只选择您感兴趣的文件,或者构建查询,使其只返回路径为“像%your\u folder\u name%”的条目