I request the ACCESS_FINE_LOCATION and ACCESS_FINE_LOCATION permission in real time
And it asks for gps information as below
There was no problem before, but I get a SecurityException error on certain devices using Android 12
Do you have any way to solve this problem?
I've searched several ways but haven't been able to find a solution yet.
Does someone know how?
thank you
if(isGpsEnable(LocationManager.GPS_PROVIDER))
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener); // error
}
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
CodePudding user response:
Ensure that you are checking to see if the permission has been granted:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
) {
// do your GPS stuff here!
}
CodePudding user response:
From android 12 android improve privacy just look below thread to implement the latest way of getting location permission.
https://proandroiddev.com/android-12-privacy-changes-for-location-55ffd8c016fd