remoorejr / cordova-plugin-camera-with-exif

Cordova Camera Plugin that will return an image as well as the EXIF data (including GPS location) on iOS and Android devices.
Apache License 2.0
38 stars 53 forks source link

Camera fails on Android 8.0 #24

Closed michaeloki closed 6 years ago

michaeloki commented 6 years ago

The plugin doesn't return a JSON object on Android 8.0 this prevents the app from getting the image uri and the error message in the failed callback shows that the issue is related to fileprovider i.e. file:// vs content://
See https://developer.android.com/reference/android/os/FileUriExposedException.html as a guide and permission issues.

pugwonk commented 6 years ago

It works fine for me on the emulator...

michaeloki commented 6 years ago

It fails on a real device.

michaeloki commented 6 years ago

I have created a pull request for this fix.

dylan-chong commented 6 years ago

Using target sdk 27 on android 8, i get this error here

07-05 09:35:05.242 4502-4502/com.foo.main W/System.err: java.io.FileNotFoundException: open failed: EACCES (Permission denied)
        at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:313)
        at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:211)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1248)
        at android.content.ContentResolver.openOutputStream(ContentResolver.java:1013)
        at android.content.ContentResolver.openOutputStream(ContentResolver.java:989)
        at org.apache.cordova.camera.CameraLauncher.writeUncompressedImage(CameraLauncher.java:1076)
        at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:547)
        at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:973)
        at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:153)
        at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:348)
        at android.app.Activity.dispatchActivityResult(Activity.java:7539)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4485)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4532)
        at android.app.ActivityThread.-wrap20(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752)
07-05 09:35:05.243 4502-4502/com.foo.main W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Using this call:

cordovaPlugin.camera.getPicture(onGetPhotoSuccess, onGetPhotoFailed, {
          correctOrientation: true,
          destinationType: Camera.DestinationType.FILE_URI,
          sourceType: type,
          saveToPhotoAlbum: true,
          targetWidth: 2048,
          targetHeight: 2048
        });

When setting saveToPhotoAlbum: false, the problem does not happen

That bug appears to be caused by this: screen shot 2018-07-05 at 10 03 22 am

On android eight we don't have access to the destination file shown in the screenshot above

michaeloki commented 6 years ago

Use the forked version I created. This issue was reported but one of the maintainers relied on an emulator instead of testing it on a real device.

On Wed, 4 Jul 2018, 23:37 Dylan Chong, notifications@github.com wrote:

Using target sdk 27 on android 8, i get this error here

07-05 09:35:05.242 4502-4502/com.thundermaps.main W/System.err: java.io.FileNotFoundException: open failed: EACCES (Permission denied) at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:313) at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:211) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1248) at android.content.ContentResolver.openOutputStream(ContentResolver.java:1013) at android.content.ContentResolver.openOutputStream(ContentResolver.java:989) at org.apache.cordova.camera.CameraLauncher.writeUncompressedImage(CameraLauncher.java:1076) at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:547) at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:973) at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:153) at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:348) at android.app.Activity.dispatchActivityResult(Activity.java:7539) at android.app.ActivityThread.deliverResults(ActivityThread.java:4485) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4532) at android.app.ActivityThread.-wrap20(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752) 07-05 09:35:05.243 4502-4502/com.thundermaps.main W/System.err: at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6938) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Using this call:

cordovaPlugin.camera.getPicture(onGetPhotoSuccess, onGetPhotoFailed, { correctOrientation: true, destinationType: Camera.DestinationType.FILE_URI, sourceType: type, saveToPhotoAlbum: true, targetWidth: 2048, targetHeight: 2048 });

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/remoorejr/cordova-plugin-camera-with-exif/issues/24#issuecomment-402562628, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUdf_pzilB7KpIB_bKH-0WiY9LQzb0Fks5uDTWdgaJpZM4SFYIH .

dylan-chong commented 6 years ago

It appears that replacing WRITE_EXTERNAL_STORAGE with READ_EXTERNAL_STORAGE inside CameraLauncher fixes the problem.