简体   繁体   中英

ACTION_LOCATION_SOURCE_SETTINGS only turn on GPS but permission is still not granted in Android 10

My app needs location, it works well in Android 9. But in Android 10, the ACTION_LOCATION_SOURCE_SETTINGS doesn't grant the permission, only turn on the GPS.

@RequiresApi(api = Build.VERSION_CODES.M)
private void goToSettings() {
    Intent myAppSettings = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(myAppSettings);
}

In manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

If I tried to use startActivityForResult , no matter what action the user does, it always returns RESULT_CANCELED

[https://developer.android.com/about/versions/10/privacy/changes]

Android 10 introduces the ACCESS_BACKGROUND_LOCATION permission.

Unlike the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions, the ACCESS_BACKGROUND_LOCATION permission only affects an app's access to location when it runs in the background. An app is considered to be accessing location in the background unless one of the following conditions is satisfied:

An activity belonging to the app is visible. The app is running a foreground service that has declared a foreground service type of location.

Perhaps you need to request the ACCESS_BACKGROUND_LOCATION permission.

Also, I found this in the documentation

ACTION_SECURITY_SETTINGS

Activity Action: Show settings to allow configuration of security and location privacy.

Which might be the activity you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM