How to open device setting form flutter app?

Viewed 2852

I want to open the setting when the user taps the button.

I can see the intent Settings.ACTION_SETTINGS defined for the setting here

I am using the package Android_intent

code:

AndroidIntent intent = AndroidIntent(
   action: 'Settings.ACTION_SETTINGS',
 );
await intent.launch();

But, I am getting the error:-

E/flutter (14266): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, No Activity found to handle Intent { act=Settings.ACTION_SETTINGS (has extras) }, null)

How to open the setting page form flutter?

3 Answers

I was using the wrong Setting intent, following is working code:-

AndroidIntent intent = AndroidIntent(
  action: 'android.settings.SETTINGS',
);
await intent.launch();

I usually use this plugin

app_settings: 3.0.1

then import it

import 'package:app_settings/app_settings.dart';

and then I use

onPressed() {
  AppSettings.openDataRoamingSettings(); //or whatever settings you want to open xD
}

Do tell if it works :)

You can also use app_settings.

onPressed: () {
          AppSettings.openDeviceSettings(
            asAnotherTask: true,
          );
        },

Should work both Android and iOS.

Read more: https://pub.dev/packages/app_settings

Related