Cordova-plugin-camera not working with Android version 8
up vote
2
down vote
favorite
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 (cordova-lib@8.1.1)
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
android cordova cordova-plugins
add a comment |
up vote
2
down vote
favorite
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 (cordova-lib@8.1.1)
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
android cordova cordova-plugins
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 (cordova-lib@8.1.1)
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
android cordova cordova-plugins
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 (cordova-lib@8.1.1)
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
android cordova cordova-plugins
android cordova cordova-plugins
asked Nov 9 at 10:36
Richard
136
136
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The issue is with our code rather than the plugin - view issue on github
We were using the following code
function captureImage()
navigator.device.capture.captureImage(captureImageSuccess, captureImageError, limit: 1);
function captureImageSuccess(mediaFiles)
uploadFile(mediaFiles[0]);
function uploadFile(mediaFile,fileType) //#F333
var win = function (r)
var options = new FileUploadOptions();
ImageURL=mediaFile.fullPath;
options.fileName = (fileType)? mediaFile.name : mediaFile.file; //#F333
options.mimeType = "multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
params.imageType = (fileType)?fileType:'Picture'; //#F333
var printName = prompt("Add a title",""); //#F644
if (printName)
params.printedName = printName;
window.resolveLocalFileSystemURL(ImageURL, function(fileEntry)
fileEntry.file(function(fileObj)
params.fileSize = ""+fileObj.size;
);
);
options.params = params;
var ft = new FileTransfer();
ft.upload(ImageURL, encodeURI("uploadURL"),win,fail,options);
Which we have replaced with
navigator.camera.getPicture(function cameraSuccess(imageUri)
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="test";
options.mimeType="multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
options.params = params;
var ft = new FileTransfer();
ft.upload(imageUri, encodeURI("https://upload.okappy.com/UploadToS3"), win, fail, options);
, function captureImageError(error)
console.debug("Unable to obtain picture: " + error, "app");
, options);
Hope that helps!
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The issue is with our code rather than the plugin - view issue on github
We were using the following code
function captureImage()
navigator.device.capture.captureImage(captureImageSuccess, captureImageError, limit: 1);
function captureImageSuccess(mediaFiles)
uploadFile(mediaFiles[0]);
function uploadFile(mediaFile,fileType) //#F333
var win = function (r)
var options = new FileUploadOptions();
ImageURL=mediaFile.fullPath;
options.fileName = (fileType)? mediaFile.name : mediaFile.file; //#F333
options.mimeType = "multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
params.imageType = (fileType)?fileType:'Picture'; //#F333
var printName = prompt("Add a title",""); //#F644
if (printName)
params.printedName = printName;
window.resolveLocalFileSystemURL(ImageURL, function(fileEntry)
fileEntry.file(function(fileObj)
params.fileSize = ""+fileObj.size;
);
);
options.params = params;
var ft = new FileTransfer();
ft.upload(ImageURL, encodeURI("uploadURL"),win,fail,options);
Which we have replaced with
navigator.camera.getPicture(function cameraSuccess(imageUri)
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="test";
options.mimeType="multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
options.params = params;
var ft = new FileTransfer();
ft.upload(imageUri, encodeURI("https://upload.okappy.com/UploadToS3"), win, fail, options);
, function captureImageError(error)
console.debug("Unable to obtain picture: " + error, "app");
, options);
Hope that helps!
add a comment |
up vote
0
down vote
The issue is with our code rather than the plugin - view issue on github
We were using the following code
function captureImage()
navigator.device.capture.captureImage(captureImageSuccess, captureImageError, limit: 1);
function captureImageSuccess(mediaFiles)
uploadFile(mediaFiles[0]);
function uploadFile(mediaFile,fileType) //#F333
var win = function (r)
var options = new FileUploadOptions();
ImageURL=mediaFile.fullPath;
options.fileName = (fileType)? mediaFile.name : mediaFile.file; //#F333
options.mimeType = "multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
params.imageType = (fileType)?fileType:'Picture'; //#F333
var printName = prompt("Add a title",""); //#F644
if (printName)
params.printedName = printName;
window.resolveLocalFileSystemURL(ImageURL, function(fileEntry)
fileEntry.file(function(fileObj)
params.fileSize = ""+fileObj.size;
);
);
options.params = params;
var ft = new FileTransfer();
ft.upload(ImageURL, encodeURI("uploadURL"),win,fail,options);
Which we have replaced with
navigator.camera.getPicture(function cameraSuccess(imageUri)
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="test";
options.mimeType="multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
options.params = params;
var ft = new FileTransfer();
ft.upload(imageUri, encodeURI("https://upload.okappy.com/UploadToS3"), win, fail, options);
, function captureImageError(error)
console.debug("Unable to obtain picture: " + error, "app");
, options);
Hope that helps!
add a comment |
up vote
0
down vote
up vote
0
down vote
The issue is with our code rather than the plugin - view issue on github
We were using the following code
function captureImage()
navigator.device.capture.captureImage(captureImageSuccess, captureImageError, limit: 1);
function captureImageSuccess(mediaFiles)
uploadFile(mediaFiles[0]);
function uploadFile(mediaFile,fileType) //#F333
var win = function (r)
var options = new FileUploadOptions();
ImageURL=mediaFile.fullPath;
options.fileName = (fileType)? mediaFile.name : mediaFile.file; //#F333
options.mimeType = "multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
params.imageType = (fileType)?fileType:'Picture'; //#F333
var printName = prompt("Add a title",""); //#F644
if (printName)
params.printedName = printName;
window.resolveLocalFileSystemURL(ImageURL, function(fileEntry)
fileEntry.file(function(fileObj)
params.fileSize = ""+fileObj.size;
);
);
options.params = params;
var ft = new FileTransfer();
ft.upload(ImageURL, encodeURI("uploadURL"),win,fail,options);
Which we have replaced with
navigator.camera.getPicture(function cameraSuccess(imageUri)
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="test";
options.mimeType="multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
options.params = params;
var ft = new FileTransfer();
ft.upload(imageUri, encodeURI("https://upload.okappy.com/UploadToS3"), win, fail, options);
, function captureImageError(error)
console.debug("Unable to obtain picture: " + error, "app");
, options);
Hope that helps!
The issue is with our code rather than the plugin - view issue on github
We were using the following code
function captureImage()
navigator.device.capture.captureImage(captureImageSuccess, captureImageError, limit: 1);
function captureImageSuccess(mediaFiles)
uploadFile(mediaFiles[0]);
function uploadFile(mediaFile,fileType) //#F333
var win = function (r)
var options = new FileUploadOptions();
ImageURL=mediaFile.fullPath;
options.fileName = (fileType)? mediaFile.name : mediaFile.file; //#F333
options.mimeType = "multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
params.imageType = (fileType)?fileType:'Picture'; //#F333
var printName = prompt("Add a title",""); //#F644
if (printName)
params.printedName = printName;
window.resolveLocalFileSystemURL(ImageURL, function(fileEntry)
fileEntry.file(function(fileObj)
params.fileSize = ""+fileObj.size;
);
);
options.params = params;
var ft = new FileTransfer();
ft.upload(ImageURL, encodeURI("uploadURL"),win,fail,options);
Which we have replaced with
navigator.camera.getPicture(function cameraSuccess(imageUri)
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="test";
options.mimeType="multipart/form-data";
var params = new Object();
params.fileName = 'AndroidPhoneUpload';
options.params = params;
var ft = new FileTransfer();
ft.upload(imageUri, encodeURI("https://upload.okappy.com/UploadToS3"), win, fail, options);
, function captureImageError(error)
console.debug("Unable to obtain picture: " + error, "app");
, options);
Hope that helps!
answered Dec 4 at 13:58
Richard
136
136
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224086%2fcordova-plugin-camera-not-working-with-android-version-8%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown