【问题标题】:Is there a way to stop alarm sound by swiping from notification in Flutter有没有办法通过从 Flutter 中的通知滑动来停止警报声音
【发布时间】:2021-12-29 05:08:40
【问题描述】:

我想在通知到来时拨打警报。我做到了,但我并没有通过滑动通知来停止警报。这是我的代码示例:

Future<void> _messageHandler(RemoteMessage message) async {
  debugPrint('Incoming notification is ${message.notification!.body}');
  FlutterRingtonePlayer.playAlarm(asAlarm: false);
  //FlutterRingtonePlayer.stop();
}

void main() async{
  HttpOverrides.global = new MyHttpOverrides();
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseMessaging.onBackgroundMessage(_messageHandler);
  runApp(MyApp());
}

那么,有什么办法可以解决这个问题吗?我正在等待您的想法,谢谢...

【问题讨论】:

    标签: android flutter mobile push-notification firebase-cloud-messaging


    【解决方案1】:
    Future<void> _messageHandler(RemoteMessage message) async {
      debugPrint('Incoming notification is ${message.notification!.body}');
      FlutterRingtonePlayer.playAlarm(asAlarm: false);
      debugPrint('afterPlay');
      Future.delayed(const Duration(seconds: 15), () {
        FlutterRingtonePlayer.stop();
      });
      debugPrint('afterStop');
    }
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2020-12-31
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    相关资源
    最近更新 更多