Hus*_*har 5 background-service 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;
}
Run Code Online (Sandbox Code Playgroud)
然后在 Flutter 方面:
class AppModel extends Model {
final _platformChannel1 =
MethodChannel('company.com/package/name');
Future<Null> dndOn() async {
await _platformChannel1.invokeMethod('AIRPLANE MODE ON');
notifyListeners();
}
Run Code Online (Sandbox Code Playgroud)
不知道IOS怎么样...
祝你好运,这比看起来更容易!
| 归档时间: |
|
| 查看次数: |
2345 次 |
| 最近记录: |