如何使用棒棒糖及之前的相机共享内部存储中存在的文件?

时间:2019-05-02 06:22:59

标签: android camera android-5.0-lollipop android-fileprovider internal-storage

我正在尝试使相机将文件存储在内部文件存储中,在Marshmellow及以上版本中一切运行正常,但在Lollipop及以下版本中,相机无法在内部存储中创建和存储文件

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
   cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mFile));
    }
 else 
    {
   Uri photoUri = FileProvider.getUriForFile(activityReference.getApplicationContext(), activityReference.getPackageName() + ".provider", mFile);
   cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    }

cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

if (fragmentReference == null)
   activityReference.startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
else
   fragmentReference.startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);

onActivityResult中,每当我传递内部文件存储中存在的文件(context.getFilesDir())时,我总是得到Activity.RESULT_CANCELED,当文件存在于外部缓存,外部文件或外部文件中时,一切正常公共目录

0 个答案:

没有答案