Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.FileNotFoundException:content://com.android.contacts/contacts/24093/photo 仅适用于旧照片_Java_Android_File_Bitmap - Fatal编程技术网

java.io.FileNotFoundException:content://com.android.contacts/contacts/24093/photo 仅适用于旧照片

java.io.FileNotFoundException:content://com.android.contacts/contacts/24093/photo 仅适用于旧照片,java,android,file,bitmap,Java,Android,File,Bitmap,我正在从手机联系人列表中获取联系人图像URI 但是,当我尝试将图像uri转换为位图时,出现了一个错误: java.io.FileNotFoundException: content://com.android.contacts/contacts/24093/photo 它与我设备上的旧照片有关,就像我拍了一张新照片一样,它显示正常 因此,可能旧照片太大或不正常,但异常显示java.io.FileNotFoundException 我如何确认这是访问权限问题 final Bitmap

我正在从手机联系人列表中获取联系人图像URI

但是,当我尝试将图像uri转换为位图时,出现了一个错误:

java.io.FileNotFoundException: content://com.android.contacts/contacts/24093/photo
它与我设备上的旧照片有关,就像我拍了一张新照片一样,它显示正常

因此,可能旧照片太大或不正常,但异常显示
java.io.FileNotFoundException

我如何确认这是访问权限问题

      final Bitmap bitmap;
      try {
        bitmap = MediaStore.Images.Media.getBitmap(ab.getContentResolver(), tryUri);
        ab.runOnUiThread(new Runnable() {
          @Override
          public void run() {
            // make sure the tag is still the one we set at the beginning of this function
            if (toSet.getTag() == urlStr) {
              toSet.setImageBitmap(bitmap);
            }
          }
        });
      } catch (FileNotFoundException e) {
        String a = "1";
      } catch (IOException e) {
        String a = "1";
      } catch (Exception e) {
        String a = "1";
      }
有两种可能:1)您使用的uri不再好了。您可以使用ContactsContract重新销售一个新的。 2) 您正在提取的联系人24093可能已不存在或已合并到另一个联系人中。因此,不再有主要联系人照片

尝试使用ContactsContract而不是getBitmap执行此操作。如果照片不存在,您将以null结束,而不是FileNotFound错误:

private void showPic(String photoUri) {
    Bitmap[] array = new Bitmap[2];
    Cursor cursor = getContentResolver().query(Uri.parse(photoUri),
            new String[] {ContactsContract.Contacts.Photo.PHOTO}, null, null, null);
    try {
        if (cursor.moveToFirst()) {
            byte[] data = cursor.getBlob(0);
            if (data != null) {
                array[0] = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
            }
        }
    } finally {
        cursor.close();
    }

    if (array[0] != null) {toSet.setImageBitmap(array[0]);}
}