Added option to disable Android photo picker

This commit is contained in:
M66B
2022-08-09 09:03:25 +02:00
parent 17f7e16651
commit 455c6e3dd7
4 changed files with 35 additions and 7 deletions

View File

@@ -3034,7 +3034,8 @@ public class FragmentCompose extends FragmentBase {
}
private void onAddImage(boolean photo) {
PackageManager pm = getContext().getPackageManager();
Context context = getContext();
PackageManager pm = context.getPackageManager();
if (photo) {
// https://developer.android.com/training/camera/photobasics
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
@@ -3049,26 +3050,28 @@ public class FragmentCompose extends FragmentBase {
});
snackbar.show();
} else {
File dir = new File(getContext().getFilesDir(), "photo");
File dir = new File(context.getFilesDir(), "photo");
if (!dir.exists())
dir.mkdir();
File file = new File(dir, working + ".jpg");
try {
photoURI = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, file);
photoURI = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(intent, REQUEST_TAKE_PHOTO);
} catch (Throwable ex) {
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
Helper.reportNoViewer(getContext(), intent, ex);
Helper.reportNoViewer(context, intent, ex);
}
}
} else {
// https://developer.android.com/reference/android/provider/MediaStore#ACTION_PICK_IMAGES
// Android 12: cmd device_config put storage_native_boot picker_intent_enabled true
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean photo_picker = prefs.getBoolean("photo_picker", true);
Intent picker = new Intent(MediaStore.ACTION_PICK_IMAGES);
picker.setType("image/*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
picker.resolveActivity(pm) != null) {
photo_picker && picker.resolveActivity(pm) != null) {
Log.i("Using photo picker");
picker.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit());
startActivityForResult(picker, REQUEST_IMAGE_FILE);
@@ -3082,7 +3085,7 @@ public class FragmentCompose extends FragmentBase {
if (intent.resolveActivity(pm) == null) // GET_CONTENT whitelisted
noStorageAccessFramework();
else
startActivityForResult(Helper.getChooser(getContext(), intent), REQUEST_IMAGE_FILE);
startActivityForResult(Helper.getChooser(context, intent), REQUEST_IMAGE_FILE);
}
}
}