How can I open location setting as image below by using android_intent or url_launcher?
I tried some ways but it did not work:
Example:
final AndroidIntent intent = new AndroidIntent(
action: 'action_view',
package: 'android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS'
);
intent.launch();
Method 1: Location Setting Popup within App To show the location popup within the app, you can use location package in your Project. Add this package by adding the following lines in your pubspec. yaml file. This code will show the following alert dialog within App.
The Android 11 option to always allow is not presented on the location permission dialog prompt. The user has to enable it manually from the app settings. This should be explained to the user on a separate UI that redirects the user to the app's location settings managed by the operating system.
You can use the android_intent
package but the action is incorrect, you have to use this :
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',);
intent.launch();
Reference: https://developer.android.com/reference/android/provider/Settings.html#ACTION_LOCATION_SOURCE_SETTINGS
You also can do it without additional dependencies like android_intent
or url_launcher
class MainActivity : FlutterActivity() {
companion object {
private const val CHANNEL = "com.myapp/intent"
const val MAP_METHOD = "settings"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == MAP_METHOD) {
startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
result.success(null)
} else {
result.notImplemented()
}
}
}
}
And if dart code:
static const platform = const MethodChannel('com.myapp/intent');
void openSettings() async {
await platform.invokeMethod('settings');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With