Starting an intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
CurrentFile = new File(getTempFileString());
CurrentUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", CurrentFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, CurrentUri);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, IMAGE_CAPTURE);
Used to work. It no longer does. My method that starts after the intent is:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
The resultCode
used to be RESULT_OK
but is now RESULT_CANCELED
.
If I stop checking the resultCode and just go past this, I find that the photo doesn't exist.
Based on CommonsWare's comment I extracted the logs. Of the 654 lines generated during this operation, four seem relevant.
2020-10-12 11:03:04.301 1471-1763/? E/MediaProvider: Creating a non-default top level directory or deleting an existing one is not allowed!
2020-10-12 11:03:04.310 477-2112/? I/AppsFilter: interaction: PackageSetting{240e1c6 com.[my app package]/10151} -> PackageSetting{193734c com.android.camera2/10124} BLOCKED
2020-10-12 11:03:04.553 390-9884/? W/ServiceManager: Permission failure: android.permission.SYSTEM_CAMERA from uid=10124 pid=11746
2020-10-12 11:03:14.097 11746-11746/? E/CAM_StateSavePic: exception while saving result to URI: Optional.of(content://[my app package].provider/external_files/[The SD card path I asked for]/1602518584301.jpg)
I am asking the file to get saved here:
new File(Environment.getExternalStorageDirectory(), getString(a.getApplicationInfo().labelRes))
This seems to be the issue.