。context.getContentResolver()openInputStream(URI);给予权限被拒绝

时间:2017-04-23 03:55:04

标签: android

我正在尝试使用自定义数组适配器查看图像。但是当我尝试使用时 。context.getContentResolver()openInputStream(URI);为了得到输入流,它会给我这个权限被拒绝的例外。

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;

    InputStream is = null;
    try {
        is = context.getContentResolver().openInputStream(uri);
    }
    catch(FileNotFoundException e){}
    BitmapFactory.decodeStream(is, new Rect (0,0,0,0), options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    try {
        is.close();
    }
    catch (IOException e){}
    try {
        is = context.getContentResolver().openInputStream(uri);
    }
    catch(FileNotFoundException e){}
    catch(SecurityException e){}
    Bitmap m = BitmapFactory.decodeStream(is, new Rect (0,0,0,0), options)

0 个答案:

没有答案