【问题标题】:Receive push notification with sound接收带声音的推送通知
【发布时间】:2016-02-25 13:26:44
【问题描述】:

我有一个 react-native 应用程序,它可以使用 react-native-gcm-android 包接收推送通知。我想在收到推送时播放声音(默认或自定义)。

我尝试了我的 gcm 有效负载的一些变体,但没有一个版本可以播放:

dataPayload = {
    'title': 'Stackoverflow',
    'badge': 'Increment',
    'alert': alert,
    'notification': {
      'subject': 'Stackoverflow',
      'message': 'Some message',
      'sound': 'default'
    }
}

dataPayload = {
    'title': 'Stackoverflow',
    'badge': 'Increment',
    'alert': 'Some text',
    'notification': {
      'subject': 'Stackoverflow',
      'message': 'Some message',
      'sound': 'android.resource://com.mypackagename.myapp/sound.mp3'
    }
}

dataPayload = {
    'title': 'Stackoverflow',
    'badge': 'Increment',
    'alert': 'Some text',
    'notification': {
      'subject': 'Stackoverflow',
      'message': 'Some message',
      'sound': true
    }
}

sound.mp3 文件位于android/app/src/res/

【问题讨论】:

标签: android push-notification google-cloud-messaging react-native


【解决方案1】:

如果您使用的是react-native-push-notificationa fix can be found here

【讨论】:

    【解决方案2】:

    声音文件应该在 /res/raw 正如doc 所说

    【讨论】:

    • 声音文件也可以从资产中使用!
    • Android 声音文件必须位于 /res/raw/,这一行在我上面提到的文档中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    相关资源
    最近更新 更多