Dhaval2404 / ImagePicker

📸Image Picker for Android, Pick an image from Gallery or Capture a new image with Camera

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImagePicker crash while capturing Camera Image and Camera Permission is Defined in Manifest

Dhaval2404 opened this issue · comments

Today, I discover a very strange crash issue. When Camera Permission is declared in Manifest and android.media.action.IMAGE_CAPTURE intent is called then the app must request CAMERA runtime permission. Otherwise, app will be crashed.

And if we remove permission from manifest then an error will no longer be reproduced.

Found below StackOverflow link which has this kind of similar issue:
https://stackoverflow.com/questions/43042725/revoked-permission-android-permission-camera/43070198

java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=4282, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.github.dhaval2404.imagepicker.sample/com.github.dhaval2404.imagepicker.ImagePickerActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:content://com.github.dhaval2404.imagepicker.sample.provider/external_files/DCIM/Camera/IMG_20190930_230312575.jpg} (has extras) } from ProcessRecord{bfa62b 30120:com.github.dhaval2404.imagepicker.sample/u0a134} (pid=30120, uid=10134) with revoked permission android.permission.CAMERA
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:content://com.github.dhaval2404.imagepicker.sample.provider/external_files/DCIM/Camera/IMG_20190930_230312575.jpg} (has extras) } from ProcessRecord{bfa62b 30120:com.github.dhaval2404.imagepicker.sample/u0a134} (pid=30120, uid=10134) with revoked permission android.permission.CAMERA
        at android.os.Parcel.createException(Parcel.java:2071)
        at android.os.Parcel.readException(Parcel.java:2039)
        at android.os.Parcel.readException(Parcel.java:1987)
        at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:3851)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1705)
        at android.app.Activity.startActivityForResult(Activity.java:5192)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
        at android.app.Activity.startActivityForResult(Activity.java:5150)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
        at com.github.dhaval2404.imagepicker.provider.CameraProvider.startCameraIntent(CameraProvider.kt:82)
        at com.github.dhaval2404.imagepicker.provider.CameraProvider.onRequestPermissionsResult(CameraProvider.kt:96)
        at com.github.dhaval2404.imagepicker.ImagePickerActivity.onRequestPermissionsResult(ImagePickerActivity.kt:87)
        at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8264)
        at android.app.Activity.dispatchActivityResult(Activity.java:8114)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886) 
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
     Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1043)
        at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:760)
        at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:583)
        at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1288)
        at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:514)

If anyone facing this issue, Kindly remove Camera Permission from Manifest for now.

<uses-permission android:name="android.permission.CAMERA" />

Issue resolved as of v1.5