开始一个意图:
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);
曾经工作。它不再这样做了。我在意图之后开始的方法是:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
resultCode
以前是,RESULT_OK
现在是RESULT_CANCELED
。
如果我停止检查 resultCode 并跳过它,我会发现照片不存在。
根据 CommonsWare 的评论,我提取了日志。在此操作期间生成的 654 行中,有 4 行似乎相关。
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)
我要求将文件保存在这里:
new File(Environment.getExternalStorageDirectory(), getString(a.getApplicationInfo().labelRes))
这似乎是问题所在。