小编Fen*_* Li的帖子

如何在 Android Q 中拍照并保存?

新编辑:

我正在开发一个 android 应用程序并希望支持 android Q。当我的应用程序在目标 API(<= 28) 中运行时,一切正常。但是在 android Q 中,当我拍照并尝试保存它时,会发生一些奇怪的事情。

当我拍摄第一张照片时,我可以在我的自定义照片选择器中找到它。但是我找不到在第一张之后拍摄的其他照片。

但是我可以通过在终端中使用 adb 找到所有照片。有人有一些建议吗?

我这样拍照:

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mCameraFilePath = MediaDataManager.getInstance().getFilePath(MediaDataManager.IMAGE, fileName);
// this function returns the img file path, like /storage/emulated/0/Android/data/<package-name>/files/Pictures/1556592144304.png
mCameraPicUri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".fileprovider", new File(mCameraFilePath));
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraPicUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

并保存照片:

try {
    File file = new File(=getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName + ".png");
    if (file.exists()) {
         file.delete();
         file.createNewFile();
    }
     InputStream inputStream = =getContentResolver().openInputStream(mCameraPicUri);
     FileOutputStream out = null;
     try {
         out = new FileOutputStream(file); …
Run Code Online (Sandbox Code Playgroud)

android photo android-10.0

5
推荐指数
1
解决办法
3357
查看次数

标签 统计

android ×1

android-10.0 ×1

photo ×1