Cannot resolve method checkSelfPermission

后端 未结 7 1096
南方客
南方客 2021-02-19 14:58

I\'m trying to make my app ready for Android 6 and now I\'m stuck to the point where you need to request and check permissions.

I tried the following from the docs:

相关标签:
7条回答
  • 2021-02-19 16:02

    Trying to use checkSelfPermission() in a Fragment with Kotlin and wondering how to get around Context being null?

    Have a look at the sample below, and remember, before the Fragment is attached to the Activity, the Context will be null.

    private fun fineLocationPermissionApproved(): Boolean {
    
        val context = context ?: return false
    
        return PackageManager.PERMISSION_GRANTED == checkSelfPermission(
            context,
            Manifest.permission.ACCESS_FINE_LOCATION
        )
    }
    
    0 讨论(0)
提交回复
热议问题