Home > Software design >  Location permission issue Android 13
Location permission issue Android 13

Time:01-27

Location permission is directly going to isAnyPermissionPermanentlyDenied on Android 13. It is not asking permission to user. Even if I grant the permission in settings also, it is going to isAnyPermissionPermanentlyDenied.

 val permissions = ArrayList<String>()
        permissions.add(Manifest.permission.ACCESS_FINE_LOCATION)
        Dexter.withActivity(this).withPermissions(permissions)
            .withListener(object : MultiplePermissionsListener {
                override fun onPermissionsChecked(report: MultiplePermissionsReport) {
                    when {
                        report.areAllPermissionsGranted() -> {
                            checkAppUpdate()
                        }
                        report.isAnyPermissionPermanentlyDenied -> {
                            startActivity(
                                Intent(
                                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                                    Uri.parse("package:"   BuildConfig.APPLICATION_ID)
                                )
                            )
                        }
                        else -> {
                            checkPermission()
                        }
                    }

                }

                override fun onPermissionRationaleShouldBeShown(
                    permissions: List<PermissionRequest>,
                    token: PermissionToken
                ) {
                    token.continuePermissionRequest()
                }
            }).onSameThread().check()

CodePudding user response:

First ask for COARSE location permission.

And only when the user allowed that ask for FINE.

CodePudding user response:

At first, Dexter is not under active maintenance anymore and I would not recommend to use it when you work on Android 13. The new way is also way more straight forward

Example:

    private val permissionList = arrayOf(
        Manifest.permission.READ_CONTACTS,
        Manifest.permission.WRITE_CONTACTS,
        Manifest.permission.CALL_PHONE
    )

    private val activityResultLauncher =
        registerForActivityResult(RequestMultiplePermissions()) { permissions ->
            if (!permissions.values.contains(false)) {
//                contactsProvider.addMockContactList()
                permissionState.value = true
                Log.d(TAG, "activityResultLauncher")
            }
        }
    private fun checkPermissions() {
        val hasPermission = permissionList.all {
            checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED
        }
        Log.d(TAG, "checkPermissions")
        if (!hasPermission) {
            activityResultLauncher.launch(permissionList)
        } else {
            getContactList()
            permissionState.value = true
        }
    }

And second, for getting location information you need two permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION. Since fine location depends on coarse location, it will get instantly revoked everytime.

  • Related