Add support to pick image from content provider

This commit is contained in:
Pfaffenrodt
2022-10-28 23:41:24 +02:00
parent 3179644fbc
commit e97f7c8645
2 changed files with 13 additions and 4 deletions

View File

@@ -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);

View File

@@ -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);