You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Richard B Knoll (JIRA)" <ji...@apache.org> on 2015/12/29 19:13:49 UTC

[jira] [Commented] (CB-10219) App crash when using camera plugin with Android platform 5.0.0 on SDK23 device

    [ https://issues.apache.org/jira/browse/CB-10219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15074132#comment-15074132 ] 

Richard B Knoll commented on CB-10219:
--------------------------------------

Thanks for filing this issue! There is already a JIRA open for this (CB-10120), so I'm going to close this as a duplicate. There is also a PR fixing it [here|https://github.com/apache/cordova-plugin-camera/pull/142] which is waiting to be merged. An explanation of the problem follows:

Basically, the issue here is a quirk within Android itself. Android M introduced runtime permissions for things like the camera. Previously, you declared them in the app manifest and were granted them at install time. None of this should be relevant to us because this plugin doesn't actually take photos; it launches the native camera application which already has permission to take photos. For that reason, we do not declare the camera permission in our manifest and everything works fine without install time or runtime permissions. However, for some mysterious reason, if you do declare the camera permission in the manifest, then you suddenly do have to request permission at runtime or you get the exception you posted (this quirk is documented [here|https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE]) . As I mentioned, we don't declare it in the manifest. Other plugins, though, can insert things into the manifest if they need to. Chances are you are using a third party plugin that needs the camera and so is inserting the permission and causing this issue.

tldr; Check out the PR and issue linked above, but if you need a quick fix you can remove whatever other plugin in your project is requesting the camera permission and the exception should go away. The PR has the "real" solution that should hopefully prevent this permission collision from happening in the future. Hope this helps!

> App crash when using camera plugin with Android platform 5.0.0 on SDK23 device
> ------------------------------------------------------------------------------
>
>                 Key: CB-10219
>                 URL: https://issues.apache.org/jira/browse/CB-10219
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, Plugin Camera
>    Affects Versions: 5.0.0
>            Reporter: Karl Kemp
>
> In my app I call the camera plugin like this:
> {code}
>     return new Promise(function (resolve, reject) {
>             //PhoneGap camera API
>             navigator.camera.getPicture(
>                 function (imageLocalFilePath) { //Success callback
>    
>                     resolve(imageLocalFilePath);
>                 },
>                 function (errorMessage)  { //Error callback
>                     reject(new Error(errorMessage));
>                 }, 
>                  { //Image capture options
>                     quality: 50,
>                     destinationType: Camera.DestinationType.FILE_URI,
>                     encodingType: Camera.EncodingType.JPEG,
>                     targetWidth: targetWidth,
>                     targetHeight: targetHeight,
>                     mediaType: Camera.MediaType.PICTURE,
>                     correctOrientation: true,
>                     saveToPhotoAlbum: useCameraRoll
>                 });
>         });
> {code}
> When this code runs on my Asus Nexus 7 running Android 6.0 (API23) I get the permission prompt as expected when I click the take photo button within the app for the first time.  I click the "Accept" button but the app immediately crashes with the following error, which seems to say that permission was denied:  
> {noformat}
> 12-17 14:27:52.083 21930-21930/com.lifecyclemobile.fivespark E/AndroidRuntime: FATAL EXCEPTION: main
>                                                                                Process: com.lifecyclemobile.fivespark, PID: 21930
>                                                                                java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.lifecyclemobile.fivespark/com.lifecyclemobile.fivespark.MainActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Android/data/com.lifecyclemobile.fivespark/cache/.Pic.jpg} (has extras) } from ProcessRecord{513cbe8 21930:com.lifecyclemobile.fivespark/u0a235} (pid=21930, uid=10235) with revoked permission android.permission.CAMERA
>                                                                                    at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
>                                                                                    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
>                                                                                    at android.app.ActivityThread.-wrap16(ActivityThread.java)
>                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
>                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
>                                                                                    at android.os.Looper.loop(Looper.java:148)
>                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5417)
>                                                                                    at java.lang.reflect.Method.invoke(Native Method)
>                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
>                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
>                                                                                 Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Android/data/com.lifecyclemobile.fivespark/cache/.Pic.jpg} (has extras) } from ProcessRecord{513cbe8 21930:com.lifecyclemobile.fivespark/u0a235} (pid=21930, uid=10235) with revoked permission android.permission.CAMERA
>                                                                                    at android.os.Parcel.readException(Parcel.java:1599)
>                                                                                    at android.os.Parcel.readException(Parcel.java:1552)
>                                                                                    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
>                                                                                    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
>                                                                                    at android.app.Activity.startActivityForResult(Activity.java:3917)
>                                                                                    at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:332)
>                                                                                    at android.app.Activity.startActivityForResult(Activity.java:3877)
>                                                                                    at org.apache.cordova.CordovaInterfaceImpl.startActivityForResult(CordovaInterfaceImpl.java:63)
>                                                                                    at org.apache.cordova.camera.CameraLauncher.takePicture(CameraLauncher.java:268)
>                                                                                    at org.apache.cordova.camera.CameraLauncher.onRequestPermissionResult(CameraLauncher.java:1205)
>                                                                                    at org.apache.cordova.CordovaInterfaceImpl.onRequestPermissionResult(CordovaInterfaceImpl.java:182)
>                                                                                    at org.apache.cordova.CordovaActivity.onRequestPermissionsResult(CordovaActivity.java:498)
>                                                                                    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6553)
>                                                                                    at android.app.Activity.dispatchActivityResult(Activity.java:6432)
>                                                                                    at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
>                                                                                    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) 
>                                                                                    at android.app.ActivityThread.-wrap16(ActivityThread.java) 
>                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
>                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
>                                                                                    at android.os.Looper.loop(Looper.java:148) 
>                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5417) 
>                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
>                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
>                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
> {noformat}
> My app is using Android platform 5.0.0 and Camera plugin 2.0.0 
> If I go into settings and manually enable the camera permission for my app, it works as expected.  It also works as expected on older versions of Android.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org