From 507bdf32c2b8ebc1f8bf5b904f870634b5b12193 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 27 Oct 2018 14:28:33 +0200 Subject: [PATCH] handle a permissions issue related to setting contact photo --- .../contacts/activities/EditContactActivity.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index 33497410..c9fccc55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -5,6 +5,7 @@ import android.app.DatePickerDialog import android.content.ClipData import android.content.ContentValues import android.content.Intent +import android.graphics.Bitmap import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle @@ -267,9 +268,16 @@ class EditContactActivity : ContactActivity() { } var imageUri = primaryUri - val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, primaryUri) + var bitmap = MediaStore.Images.Media.getBitmap(contentResolver, primaryUri) if (bitmap == null) { imageUri = backupUri + bitmap = MediaStore.Images.Media.getBitmap(contentResolver, backupUri) ?: return + + // we might have received an URI which we have no permission to send further, so just copy the received image in a new uri (for example from Google Photos) + val newFile = getCachePhoto() + val fos = newFile.outputStream() + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos) + imageUri = getCachePhotoUri(newFile) } lastPhotoIntentUri = getCachePhotoUri()