[英]Android URI error java.io.FileNotFoundException: No content provider: http://
[英]java.io.FileNotFoundException: content://com.android.contacts/contacts/24093/photo for old photos only
我正在從電話聯系人列表中獲取聯系人圖像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]);}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.