I am using cordova-plugin-camera to access the camera in Android. This was working fine until I changed the Target SDK version to API 26: Android 8.0 (Oreo) in order to be able to upload to the Google play store which now requires this version or above.
The error I get is
file:///data/user/0/{mypackage}/cache/Capture.jpg exposed beyond app through ClipData.Item.getUri()
which I believe is due to a change in how apps can access the file system from Android Nougat - see android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData().
I have tried fixing the issue with different versions of cordova, cordova android and the camera plugin as per https://github.com/ionic-team/ng-cordova/issues/1381 but in each case as soon as I change the TargetSDK to 26 I get the same error on an Android 8 phone.
I have added the following to my AndroidManifest.xml file
<provider android:authorities="com.okappy.okappy.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
</provider>
And I have checked that I have a camera_provider_paths.xml with the following
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
I have also tried editing the following lines in cordova/camera/CordovaURI.java to forcibly ignore the fileUri but it made no difference
public Uri getCorrectUri()
{
/*if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
return androidUri;
else
return fileUri;
*/
return androidUri;
}
I have the following versions
8.1.2 ([email protected])
android 7.1.2
cordova-plugin-camera 4.0.3
- cordova-plugin-console 1.0.3
- cordova-plugin-file 6.0.1
I am using Compile SDK version 28.0.3, MinumumSDK version of 21 and TargetSDK version of 26.
Thanks in advance for your help