从“下载”文件夹中自动检索图像并在ImageView中显示

时间:2018-03-29 11:07:31

标签: java android android-sqlite

我有一个下载文件夹,其中有很多图像。我想从该文件夹中获取单个图像并显示到ImageView中。代码如下所示我将此代码用于 onCreate()方法。这样就无需从文件夹中进行选择。我已经给了必要的许可。但是获取java.io.FileNotFoundException:内容中的多个项目://给定代码的media / external / images / media。

image = MediaStore.Images.Media.getBitmap(this.getContentResolver(),selectedimg);

Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Uri selectedImage = intent.getData();
    String[] filePaths = {MediaStore.Images.Media.DATA}; 
    Cursor c = getContentResolver().query(selectedImage, filePaths, null, null, null);
    c.moveToFirst();
    int columnIndex = c.getColumnIndex(filePaths[0]);
    String picturePath = c.getString(columnIndex);
    Log.e(TAG, "onActivityResult: "+picturePath );
    c.close();
    Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
    try {


        Uri selectedimg = intent.getData();
        image = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedimg);
        Bitmap resizedBmp = Helpers.resizeForPreview(image);
        selectImage.setImageBitmap(resizedBmp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Log.e("path of image ", picturePath + " "+ Uri.parse(picturePath));

    selectImage.setImageBitmap(thumbnail);

0 个答案:

没有答案