0

在我的应用程序中,我想仅显示来自 Gridview 中 Camera 文件夹的图像。我编写了以下代码来导入图像:-

String[] projection = { MediaStore.Images.Thumbnails._ID, };

        Cursor mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null ); 

    if (mImageCursor != null)
    {

        mImageCursor.moveToFirst();

        for (int i = 0; i < mImageCursor.getCount(); i++)
        {
            Images im=new Images();
            int imageId = mImageCursor.getInt((mImageCursor.getColumnIndex( MediaStore.Images.Media._ID)));
            Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), 
                    imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
            im.setBitmap(bm);
            arrayOfImages.add(im);

            mImageCursor.moveToNext();
        }
    }

但是此代码从图库中导入所有图像。但我只想从相机文件夹中导入图像。p

4

1 回答 1

4

如果您只想要相机图像,您可以通过在存储桶名称上过滤相机图像来获取相机图像列表。在这种情况下,您可以阅读缩略图并将其显示在您自己的活动中并要求用户选择。

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String[] projection = {
                MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
                MediaStore.Images.Media.DISPLAY_NAME
        };
        String selection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ?";
        String[] selectionArgs = new String[] {
            "Camera"
        };
        Cursor mImageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection, selection, selectionArgs, null);

        while (mImageCursor.moveToNext()) {
            Log.d("TestActivity", mImageCursor.getString(1) + "    " + mImageCursor.getString(2));

        }
    }
于 2013-02-06T10:49:13.450 回答