Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location permission android 12 #748

Open
jackyhieu1211-hn opened this issue Oct 3, 2021 · 4 comments
Open

Location permission android 12 #748

jackyhieu1211-hn opened this issue Oct 3, 2021 · 4 comments

Comments

@jackyhieu1211-hn
Copy link

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.

  • Checks all given permissions have been granted.
  • Params:
  • grantResults – results
  • Returns:
  • returns true if all permissions have been granted.

Please help me.

Screen Shot 2021-10-03 at 15 53 48

@jackyhieu1211-hn
Copy link
Author

@hotchemi Please check.thank you very much

@hotchemi
Copy link
Member

hotchemi commented Oct 4, 2021

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

@jackyhieu1211-hn
Copy link
Author

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants