简体   繁体   中英

Permission dialog is not showing for the INTERNET permission using Dexter Library in android

this is the code that i wrote to check the permissions. but the inte.net 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"/>

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 INTE.NET has:

Protection level: normal

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM