飞行模式维修颤振

问题描述 投票:0回答:1
  • 基本上我想在单击按钮时打开/关闭飞行模式服务扑朔迷离。在互联网上找不到任何解决方案。找不到任何飞镖库
flutter background-service
1个回答
0
投票

您是在开发Android还是IOS或同时开发两者?在Android中,您将需要使用MethodChannel在本地进行大量工作,以便在Flutter和Android之间进行通信。然后,您将需要使用所需的UI从Flutter调用本机Notification.Service。

因此在android方面,您的代码将如下所示:

 new MethodChannel(getFlutterView(), CHANNEL1).setMethodCallHandler(new MethodCallHandler() {
            final NotificationManager mNotificationManager = 
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


     @Override
     public void onMethodCall(@NonNull MethodCall methodCall, @NonNull Result result) {

                switch (methodCall.method) {
                    case "AIRPLANE MODE ON":
                        assert mNotificationManager != null;
          mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
break;
}

然后在Flutter一侧:

class AppModel extends Model {
  final _platformChannel1 =
      MethodChannel('company.com/package/name');

  Future<Null> dndOn() async {
    await _platformChannel1.invokeMethod('AIRPLANE MODE ON');
    notifyListeners();
  }

不确定IOS ...

祝你好运,比看起来容易!

© www.soinside.com 2019 - 2024. All rights reserved.