Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPickImageChooserIntent permission bug #71

Closed
spidfire opened this issue May 17, 2016 · 7 comments
Closed

getPickImageChooserIntent permission bug #71

spidfire opened this issue May 17, 2016 · 7 comments

Comments

@spidfire
Copy link

I got some errors on my nexus 5(droid-6.0.1) while using the getPickImageChooserIntent because when I chose the camera I did not have enough permissions. So I used the code placed below to fix it. Maybe this can be useful for someone else (or could be integrated into the library).

It's a bit dirty because it asks you to give it permissions regardless of choosing the camera. If someone has a more clean solution I like to hear it.

if(android.os.Build.VERSION.SDK_INT >= 23){
  if (activity.checkSelfPermission(android.Manifest.permission.CAMERA)
    != PackageManager.PERMISSION_GRANTED) {
      page_fragment.requestPermissions(arrayOf(Manifest.permission.CAMERA), 3333);
  }
}
@ArthurHub
Copy link
Owner

Did you use the standard Android camera?
Did you get the error right after selecting the camera in the chooser? did the camera app opened?

@spidfire
Copy link
Author

I guess I use the default camera from google, and the error is just after the intent is fired, but from the operating system. Something with with revoked permission android.permission.CAMERA

@ArthurHub
Copy link
Owner

Strange.. I never experienced it..
Also it doesn't make sense as the app itself doesn't use the camera, it request the camera app for an image..
Not sure what to do as I don't want to always request this permission.. 😕

@spidfire
Copy link
Author

Maybe it could be because I use the camera in an other part of the app to scan barcodes?

@ArthurHub
Copy link
Owner

Holly shit, you are right, when I added <uses-permission android:name="android.permission.CAMERA"/> to the manifest choosing camera in the picker stopped working 😱
I will document this behavior, ****ing Android.

@ArthurHub
Copy link
Owner

Hmmm... I changed the camera intent action from MediaStore.ACTION_IMAGE_CAPTURE to MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA and it started working in the emulator, which should actually do the same thing...
Can you copy the code from CropImage.getPickImageChooserIntent and change the camera capture captureIntent and see if it will work?

@ArthurHub
Copy link
Owner

Digging a little deeper.

  1. My comment on using MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA is irrelevant, it doesn't capture an image, just opens the camera app.
  2. This is the designed behavior by Android as described in the StackOverflow question. see quote below from Android developer.
  3. Requesting camera permissions before the chooser intent is the only approach possible.
  4. It maybe better UX to separate pick from camera and pick from gallery buttons so not to request the permissions unless the user really wants camera.
  5. I will add the required permissions handling to the library for future and document this issue.

“This is intended behavior to avoid user frustration where they revoked the camera permission from an app and the app still being able to take photos via the intent. Users are not aware that the photo taken after the permission revocation happens via different mechanism and would question the correctness of the permission model. This applies to MediaStore.ACTION_IMAGE_CAPTURE, MediaStore.ACTION_VIDEO_CAPTURE, and Intent.ACTION_CALL the docs for which document the behavior change for apps targeting M."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants