Home > Software engineering >  Permission dialog is not showing for the INTERNET permission using Dexter Library in android
Permission dialog is not showing for the INTERNET permission using Dexter Library in android

Time:01-15

this is the code that i wrote to check the permissions. but the internet permission is always granted, and the dialog only asks for location permission.

import android.Manifest
import com.karumi.dexter.Dexter
import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionDeniedResponse
import com.karumi.dexter.listener.PermissionGrantedResponse
import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.single.PermissionListener

Dexter.withContext(this)
        .withPermissions(
            Manifest.permission.INTERNET,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION
        )
        .withListener(object : MultiplePermissionsListener {
            override fun onPermissionsChecked(p0: MultiplePermissionsReport?) {
                p0?.let {
                    if (p0.areAllPermissionsGranted()) {

                        getWeather()
                        getForecast()

                    }
                }
            }

            override fun onPermissionRationaleShouldBeShown(
                p0: MutableList<PermissionRequest>?,
                p1: PermissionToken?
            ) {
                p1?.continuePermissionRequest()

            }

        }).check()

and these are the permissions that I have added to the Manifest file:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

CodePudding user response:

You only need to request runtime permissions for dangerous permissions.

For example, if you look at the documentation for ACCESS_FINE_LOCATION, you will see that it has:

Protection level: dangerous

So you need to request that permission at runtime, in addition to having a manifest <uses-permission> element for it.

Conversely, the documentation for INTERNET has:

Protection level: normal

You do not need to request that permission at runtime, and trying to do so will not work.

  • Related