如何从Flutter应用程序中打开设备设置?

3

当用户点击按钮时,我希望能打开设置。

我可以看到 Settings.ACTION_SETTINGS 这个意图已经在这里定义了(链接)

我正在使用 Android_intent 包。

代码:

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

但是,我遇到了错误:-
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)

如何从Flutter中打开设置页面?
3个回答

4

我使用了错误的设置意图,以下是有效的代码:

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

1

你也可以使用app_settings

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

应该在Android和iOS上都能工作。

阅读更多:https://pub.dev/packages/app_settings


0

我通常使用这个插件

app_settings: 3.0.1

然后导入它

import 'package:app_settings/app_settings.dart';

然后我使用

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

如果它有效,请告诉我 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接