【问题标题】:Getting sound for notification on emulator, but notification isn't displaying(It does on physical device) (Android在模拟器上获取通知的声音,但未显示通知(它在物理设备上显示)(Android
【发布时间】:2021-07-15 03:46:57
【问题描述】:

通知不在模拟器上显示,而是在物理设备上。我仍然可以听到设备的声音。

    useEffect(() => {
      PushNotification.createChannel(
        {
          channelId: "fcm_fallback_notification_channel", // (required)
          channelName: "My channel", // (required)
          channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
          playSound: false, // (optional) default: true
          soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
          importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
          vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
        },
        (created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
      );

      PushNotification.channelExists('fcm_fallback_notification_channel', function (exists) {
        console.log(exists); // true/false
      });

      PushNotification.getChannels(function (channel_ids) {
        console.log(channel_ids); // ['channel_id_1']
      });
      const unsubscribe = messaging().onMessage(async (remoteMessage) => {
        console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
        PushNotification.localNotification({
          title: remoteMessage.notification.title,
          message: remoteMessage.notification.body,
          vibrate: true,
          vibration: 300,
          playSound: true,
          soundName: 'default',
          actions: ["Yes", "No"],
          channelId:"fcm_fallback_notification_channel"
        })
      });
      return unsubscribe;
    }, []);

这是显示通知的代码。我也得到了 console.log()

【问题讨论】:

    标签: android react-native react-native-android react-native-firebase react-native-push-notification


    【解决方案1】:

    推送通知可能无法在 Android 模拟器和 iOS 模拟器中正常工作,因此您应该只在物理设备上测试通知。

    如果您使用 FCM 消息传递,那么您可以在他们的文档中看到有关通知可以发送到真实设备的信息。

    【讨论】:

    • 呃,太糟糕了。谢谢你。我们正在让它成功显示在设备上。只是不在模拟器上。
    猜你喜欢
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多