From e97f7c8645c05e5e854c76724e9067f75b29bc8e Mon Sep 17 00:00:00 2001 From: Pfaffenrodt Date: Fri, 28 Oct 2022 23:41:24 +0200 Subject: [PATCH] Add support to pick image from content provider --- .../protect/card_locker/LoyaltyCardEditActivity.java | 10 +++++++--- .../main/java/protect/card_locker/ScanActivity.java | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java index 3f3eb39d0..d0f1cb335 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java @@ -1186,11 +1186,15 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity { throw new IllegalArgumentException("Unknown ID type " + v.getId()); } - Intent i = new Intent(Intent.ACTION_PICK); - i.setType("image/*"); + Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); + photoPickerIntent.setType("image/*"); + Intent contentIntent = new Intent(Intent.ACTION_GET_CONTENT); + contentIntent.setType("image/*"); + Intent chooserIntent = Intent.createChooser(photoPickerIntent, getString(R.string.addFromImage)); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { contentIntent }); try { - mPhotoPickerLauncher.launch(i); + mPhotoPickerLauncher.launch(chooserIntent); } catch (ActivityNotFoundException e) { Toast.makeText(getApplicationContext(), R.string.failedLaunchingPhotoPicker, Toast.LENGTH_LONG).show(); Log.e(TAG, "No activity found to handle intent", e); diff --git a/app/src/main/java/protect/card_locker/ScanActivity.java b/app/src/main/java/protect/card_locker/ScanActivity.java index 13119515e..1e86981e0 100644 --- a/app/src/main/java/protect/card_locker/ScanActivity.java +++ b/app/src/main/java/protect/card_locker/ScanActivity.java @@ -225,8 +225,13 @@ public class ScanActivity extends CatimaAppCompatActivity { public void addFromImage(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); + Intent contentIntent = new Intent(Intent.ACTION_GET_CONTENT); + contentIntent.setType("image/*"); + + Intent chooserIntent = Intent.createChooser(photoPickerIntent, getString(R.string.addFromImage)); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { contentIntent }); try { - photoPickerLauncher.launch(photoPickerIntent); + photoPickerLauncher.launch(chooserIntent); } catch (ActivityNotFoundException e) { Toast.makeText(getApplicationContext(), R.string.failedLaunchingPhotoPicker, Toast.LENGTH_LONG).show(); Log.e(TAG, "No activity found to handle intent", e);