flutter - 飞行模式服务颤抖
问题描述
- 基本上我想在颤动中单击按钮时设置飞行模式服务的开/关。在互联网上找不到任何解决方案。找不到任何飞镖库
解决方案
您是为 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...
祝你好运,这比看起来容易!
推荐阅读
- laravel-4 - 从 laravel 控制器输出中仅获取所需列数据的计数
- javascript - 在 javascript 三等号中,首先检查什么?类型或值?
- python - 在 python 中的大型列表操作中具有更高的性能
- python-3.x - Python 类属性计数器未正确递增
- r - 需要有条件地将函数应用于字符矩阵中的每个元素
- java - Java:基于各种操作在 GUI 中获取和设置像素
- rxjs - RxJs 6:管理数组迭代和延迟
- node.js - Heroku Node.js 应用程序上的 WebSocket 和多个 Dyno 使用 Redis
- android - 嗨,我在使用意图向特定群组发送 whatsapp 消息时遇到问题
- python - 使用经纬度计算两点之间的距离时结果的巨大差异