permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.22k stars 1.44k forks source link

Location permission android 12 #748

Open jackyhieu1211-hn opened 3 years ago

jackyhieu1211-hn commented 3 years ago

Location permission android 12

-- Hello admin. I checking android 12 and have a problem: In android 12. App must request both permission ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION

My code:

@NeedsPermission(
    Manifest.permission.ACCESS_FINE_LOCATION,
    Manifest.permission.ACCESS_COARSE_LOCATION
)
fun getLocation() {
    // Code here
 }

 @OnPermissionDenied(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
fun getLocationDenied() {
    // Code here
}

When I choose option Approximate -> While using the app

Actual results: OnPermissionDenied called. Expected results : getLocation() will call

=> Reason: method verifyPermissions in class PermissionUtils checking.

Please help me.

Screen Shot 2021-10-03 at 15 53 48
jackyhieu1211-hn commented 3 years ago

@hotchemi Please check.thank you very much

hotchemi commented 2 years ago

Thx for the report, we should address this issue before Android 12. Just in case which module are you using right now?

jackyhieu1211-hn commented 2 years ago

@hotchemi

I made a temporary fix as follows

@OnPermissionDenied(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
fun getLocationDenied() {
    checkAccessCoarseLocation()
}

@OnNeverAskAgain(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
fun onNeverAskLocationAgain() {
    checkAccessCoarseLocation()
}

private fun checkAccessCoarseLocation() {
    if (context?.isAccessCoarseLocationGranted() == true) {
        getLocation()
    } else {
        Log.e("Error", "Permission")
    }
}

fun Context.isAccessCoarseLocationGranted(): Boolean {
if (isAndroidS().not()) return false
return PermissionUtils.hasSelfPermissions(this, Manifest.permission.ACCESS_COARSE_LOCATION)
}

fun isAndroidS(): Boolean {
return Build.VERSION.SDK_INT >= 31
}
vipin5605 commented 1 year ago

@hotchemi Is this sorted ?? From this month all app updates should target API 31 or above.