Я пытаюсь сделать снимок и сохранить его во внутреннем виде с помощью следующего кода:
public void startCamera() {
picPath = getFilesDir() + File.separator + "AitrixShot" + ".jpg";
if (Build.VERSION.SDK_INT >= 23) {
if (!hasCameraPhoneAuth()) {
mActivity.requestPermissions(authCameraArr, authCameraRequestCode);
return;
}
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT > 24) {
ContentValues contentValues = new ContentValues(1);
contentValues.put(MediaStore.Images.Media.DATA, picPath);
Uri uri = mActivity.getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, contentValues);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
mActivity.startActivityForResult(intent, FlyManager_TAG_LIST.TAKE_PHOTO_REQUEST);
}
}
Я также добавляю провайдера в AndroidManifest.xml
, как показано ниже:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".CoverActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_path" />
</provider>
.
.
.
Иprovider_path.xml
выглядит следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path path="Android/data/com.example.aitrixflymanager/" name="files_root" />
<files-path path="." name="file_root" />
</paths>
Но все равно отображается следующее сообщение об ошибке:
2019-02-21 16:35:55.870 6177-6177/? E/CAM_StateSavePic: exception while saving result to URI: Optional.of(content://media/internal/images/media/191)
java.io.FileNotFoundException: Can't access /data/user/0/com.example.aitrixflymanager/files/AitrixShot/plane_shot_20190221_163548.jpg
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:144)
at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:625)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1267)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:1009)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:985)
at com.android.camera.captureintent.state.StateSavingPicture.onEnter(StateSavingPicture.java:85)
at com.android.camera.captureintent.stateful.StateMachineImpl.jumpToState(StateMachineImpl.java:63)
at com.android.camera.captureintent.stateful.StateMachineImpl.processEvent(StateMachineImpl.java:112)
at com.android.camera.captureintent.state.StateReadyForCapture$31.onClick(StateReadyForCapture.java:943)
at android.view.View.performClick(View.java:6305)
at android.view.View$PerformClick.run(View.java:24840)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Я что-то пропустил?Заранее спасибо.