Reputation: 95
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();
Upvotes: 7
Views: 4901
Reputation: 1790
For both iOS and Android platforms, you can use the app_settings
plugin - https://pub.dev/packages/app_settings
Upvotes: 1
Reputation: 29438
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');
}
Upvotes: 3
Reputation: 103381
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();
Upvotes: 11