1
votes

I have a react-native app which can receive push notifications with the react-native-gcm-android package. I want to play a sound (wether default or a custom) when I receive a push.

I tried some variations of my gcm payload, but none of the versions plays something:

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
    }
}

The sound.mp3 file is located under android/app/src/res/

2
You should put your mp3 file inside raw folder. Refer developer.android.com/guide/topics/resources/…Much Overflow

2 Answers

0
votes

If you're using react-native-push-notification, a fix can be found here

-2
votes

sound file should be in /res/raw as doc says