Android marshmallow request permission?

后端 未结 24 2098
無奈伤痛
無奈伤痛 2020-11-21 06:40

I am currently working on an application that requires several \"dangerous\" permissions. So I tried adding \"ask for permission\" as required in Android Marshmallow(API Lev

24条回答
  •  一向
    一向 (楼主)
    2020-11-21 07:03

    If you're using AndroidX Activity 1.2.0 or AndroidX Fragment 1.3.0:

    There are new Activity Result APIs that you can use to ask for permissions:

    val launcher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
        if (isGranted) {
            // Permission granted. Do the tasks.
        }
    }
    launcher.launch(Manifest.permission.ACCESS_FINE_LOCATION)
    

提交回复
热议问题