ChiliLabs / ChiliPhotoPicker

Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.
Apache License 2.0
405 stars 45 forks source link

BUG: Just crashes #9

Closed bartekpacia closed 4 years ago

bartekpacia commented 4 years ago

I simply put implementation "com.github.ChiliLabs:ChiliPhotoPicker:0.2.0" in my app/build.gradle and app started crashing with this exception:

java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.sec.android.app.camera/.Camera clip={text/uri-list U:content://pl.baftek.discoverrudy.fileprovider/Comment%20images/commentphoto_20191120_192059_6067355174982695808.jpg} (has extras) } from ProcessRecord{d346b7fd0 20377:pl.baftek.discoverrudy/u0a281} (pid=20377, uid=10281) with revoked permission android.permission.CAMERA

Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:2118) at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:892) at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:662) at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1511) at com.android.server.am.ActivityStarter.execute(ActivityStarter.java:603)

Code that causes this to happen:

private fun dispatchTakePictureIntent(imageView: View) {
        val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)

        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(packageManager) != null) {
            // Create the File where the photo should go
            photoFile = try {
                createImageFile()
            } catch (e: IOException) {
                // Error occurred while creating the File
                e.printStackTrace()
                null
            }

            // Continue only if the File was successfully created
            if (photoFile != null) {
                val photoUri: Uri = FileProvider.getUriForFile(
                    this,
                    "pl.baftek.discoverrudy.fileprovider",
                    photoFile!!
                )
                lastImageView = imageView.id

                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri)
                startActivityForResult(takePictureIntent, 1)
            }
        }
    }

I've tested it and I'm certaing that implementation of this library is the only reason why my app crashes. When I write implementation ..., app crashes while executing the aforementioned block of code. I totally don't have any idea why this thing happens. It's a pity, because I'm currenly looking for a lib like this.

APetjko commented 4 years ago

That's because you don't have permission

bartekpacia commented 4 years ago

Could you elaborate a bit?

APetjko commented 4 years ago

Your app doesn't have permission to use camera, so it crashes.

In library's README is written "Takes responsibility for all needed permissions", and maybe it was a bit misleading. It takes responsibility when picker is shown. If you start intent for camera from somewhere else in your app, you should check permission on your own. And as I can see in your function you don't do this

bartekpacia commented 4 years ago

Thanks, I'll request the permissions and try again.