android - 默认 Android 12 相机,对所有文件没有访问管理 ResultCode 始终为 0

标签 android android-studio android-12

默认的 Android 12 相机对所有文件没有访问管理,结果代码始终为 0。但是,如果使用允许管理所有文件结果代码 1 的相机。无论如何要解决这个问题吗?谢谢您

路径=“/存储/模拟/0/Android/media/bla/”;

@OnClick(R.id.btn_photo_ktp) 无效 btn_photo_ktp() {

File file = new File(Util.PATH_IMG, "img.img");
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri outPutfileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outPutfileUri);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, 1);

}

@覆盖 公共(public)无效onActivityResult(int requestCode,int resultCode,最终Intent Intent ){

super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 1) {
  if (resultCode == Activity.RESULT_OK) {
  }
}

}

最佳答案

Uri.fromFile(file)

不要使用 Uri.fromFile()。

使用 FileProvider 获取相机应用程序的可用 uri。

关于android - 默认 Android 12 相机,对所有文件没有访问管理 ResultCode 始终为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70890758/

相关文章:

android - 如何从 Android 中的图库中删除文件?

android - 在 FCM 中检索用于群发消息的 notification_key 时出错

android - 关于Android studio中gms-play-services appindexing更新到10.2.0

安卓 12 : Detect if user disables/enables camera and microphone

android - 为什么我在 Android 12 模拟器上运行时在日志中看到 EGL_emulation app_time_stats?

android - 如何从 RecyclerView Adapter 调用 ViewModel.delete?

java - 按时间对来自 2 个或更多不同来源的帖子进行排序

java - 错误: cannot find symbol class Compilation

android - 程序类型已经存在 : android. support.v13.view.DragStartHelper$1

android - windowSplashScreenAnimationDuration 有什么作用?