How to open location permission settings in Android 30?

Viewed 4929

I want to open directly location permission settings on button click android 30. How can I open?

enter image description here

Below is my code. this navigates me on permission page,

final Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + context.getPackageName()));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(i);
2 Answers

First request permission for ACCESS_FINE_LOCATION (or coarse). Then if you got the permission, request permission for ACCESS_BACKGROUND_LOCATION. It will open directly the app location settings but only if you have Target SDK 30.

Since now, there is no way to open directly permission selection page in android. Android 11 provides deep linking to open permission selection page directly if user ask for background location.

Otherwise there is no other way to open permission selection page directly.

Related