googlesamples / easypermissions

Simplify Android M system permissions
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
9.87k stars 1.46k forks source link

NullPointerException #226

Closed loihd closed 6 years ago

loihd commented 6 years ago

Basic Information

Device type: Defy Mini OS version: 4.3.1 EasyPermissions version: 1.2.0

Describe the problem

Crashlytics reported this issue. Please take a look

Code and logs

Code

 @AfterPermissionGranted(RC_CONTACTS)
    private fun requestLocationPermission() {
        val perms = arrayOf(READ_CONTACTS, WRITE_CONTACTS)
        if (hasPermissions(this, *perms)) {
            getPhones()
        } else {
            requestPermissions(this, getString(R.string.msg_rationale_contacts),
                    RC_CONTACTS, *perms)
        }
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>,
                                            grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        onRequestPermissionsResult(requestCode, permissions, grantResults, this)
    }

Logs

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dmobisoft.contacts.update/pub.devrel.easypermissions.AppSettingsDialogHolderActivity}: java.lang.NullPointerException
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
       at android.app.ActivityThread.access$600(ActivityThread.java:141)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:5103)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:525)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
       at dalvik.system.NativeStart.main(NativeStart.java)

Caused by java.lang.NullPointerException
       at pub.devrel.easypermissions.b.a(Unknown Source)
       at pub.devrel.easypermissions.AppSettingsDialogHolderActivity.onCreate(Unknown Source)
       at android.app.Activity.performCreate(Activity.java:5133)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
       at android.app.ActivityThread.access$600(ActivityThread.java:141)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:5103)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:525)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
       at dalvik.system.NativeStart.main(NativeStart.java)
samtstern commented 6 years ago

@loihd this mentions AppSettingsDialogHolderActivity which is not part of the standard flow and only launches when you use the "permissions permanently denied" flow and redirect the user to settings. Can you show the code that launches it?

loihd commented 6 years ago

I didn't launch it. My app only asks for access contacts permission. You can see in the code that I mentioned above. It must call the getPhones()function instead of asking for the permission since this device is Android 4.3.1. It's weird.

SUPERCILEX commented 6 years ago

You're on Android 4.3.1? It shouldn't request permissions at all before Android 6.0... where else are you calling EP APIs?

loihd commented 6 years ago

I only asked the permission with the code above. Nothing else. Crashlytics reported this issue. This device is rooted. But we should prevent the crash issue. You can see the screenshot here: crashlytics

SUPERCILEX commented 6 years ago

Oh, yeah, I don't think we can do anything about that. @samtstern?

samtstern commented 6 years ago

Yeah @loihd unfortunately there's nothing we can really do for an OS that old on a rooted device.

In your case you may want to try just using the raw Android permissions API to try and get more contro.

DeweyReed commented 6 years ago

Same crash but on Nexus 4 with Android 6.0.1.

Caused by java.lang.NullPointerException: Attempt to invoke direct method 'void pub.devrel.easypermissions.b.a(java.lang.Object)' on a null object reference
       at pub.devrel.easypermissions.AppSettingsDialog.fromIntent(Unknown Source)
       at pub.devrel.easypermissions.AppSettingsDialogHolderActivity.onCreate(Unknown Source)
       at android.app.Activity.performCreate(Activity.java:6280)

Crash point is here. It seems because the intent doesn't have dialog extra. But after I check the source code, this intent is guaranteed to have that extra. It's weird.

mianaliasjad commented 6 years ago

Same crash but on Nexus 4 with Android 6.0.1.

529523346 commented 5 years ago

Same crash but on CAM-TL00 with Android 6.0