React-native-push-notification: How to create android notifications that vibrate and appear

Created on 1 Jun 2016  ·  5Comments  ·  Source: zo0r/react-native-push-notification

I've got basic push notifications work on both IOS and Android (thanks!!). The IOS ones are much nicer though. I can't seem to get android to vibrate or show the notification on screen without swiping down from the top of the home screen.

So far this payload is working in android:

notification: {"sound": "default", "icon": "new_message", "color": "#18d821"}
data: {... some other stuff}

It plays a sound and the color of the background of the icon is green. The icon doesn't seem to display properly, but that might be something I did to the images.

I'd like to make the notification appear on screen, like in IOS. And I'd like it to vibrate. I've obviously read the docs but can't find an answer. I'm wondering if this is something that has to be done natively and cannot be controlled from a notification.

Anyone managed to get Android notifications working in a similar way to IOS?

Most helpful comment

Ok, got it working. Thanks for your help. To clarify, the push message looks like this:

{
  "to": "token",
  "data": {
    "message": "this message text",
    "sound": "default",
    "icon": "new_message",
    "color": "#18d821",
    "data": {
      "some-extra": "data"
    }
  }
}

I had to add some stuff to my android app that I found here. Specifically:

To app/build.gradle:

apply plugin: 'com.google.gms.google-services'
...
compile 'com.google.android.gms:play-services-gam:8.1.0'

To android/build.gradle:
classpath 'com.google.gms:google-services:1.4.0-beta3'

To manifest.xml:

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
...
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

All 5 comments

I had the same problem, try removing your notification element from the
payload

On Thu, Jun 2, 2016, 1:59 AM Nick Pomfret [email protected] wrote:

I've got basic push notifications work on both IOS and Android (thanks!!).
The IOS ones are much nicer though. I can't seem to get android to vibrate
or show the notification on screen without swiping down from the top of the
home screen.

So far this payload is working in android:

notification: {"sound": "default", "icon": "new_message", "color": "#18d821"}
data: {... some other stuff}

It plays a sound and the color of the background of the icon is green. The
icon doesn't seem to display properly, but that might be something I did to
the images.

I'd like to make the notification appear on screen, like in IOS. And I'd
like it to vibrate. I've obviously read the docs
https://developers.google.com/cloud-messaging/http-server-ref#interpret-downstream
but can't find an answer. I'm wondering if this is something that has to be
done natively and cannot be controlled from a notification.

Anyone managed to get Android notifications working in a similar way to
IOS?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/zo0r/react-native-push-notification/issues/84, or mute
the thread
https://github.com/notifications/unsubscribe/AQmB1OgBJJHMDUlO_CqNrqanimouhDzmks5qHdapgaJpZM4Ir3pv
.

So what does your payload look like? If I take out the notification element I get no notification.

Hi,

This is the payload that I use to get it vibrates:

{
  "data" : {
      "title" : "<Title>",
      "message": "<message>",
      "other" : "<other>",
  },  "to" : "<your push token>"
}

This is the payload when I get notification without vibrating:

{
  "to" : "<push token>", 
  "priority" : "normal",
  "notification" : {
    "body" : "<message body>",
    "title" : “<message title>”, 
  }
}

Hope it works the same for you.

Thanks for the reply. Your suggestion didn't work for me though. No notification and the response I get back from gcm-http.googleapis.com wasn't even well formed (just the text "to\n" !?).

Ok, got it working. Thanks for your help. To clarify, the push message looks like this:

{
  "to": "token",
  "data": {
    "message": "this message text",
    "sound": "default",
    "icon": "new_message",
    "color": "#18d821",
    "data": {
      "some-extra": "data"
    }
  }
}

I had to add some stuff to my android app that I found here. Specifically:

To app/build.gradle:

apply plugin: 'com.google.gms.google-services'
...
compile 'com.google.android.gms:play-services-gam:8.1.0'

To android/build.gradle:
classpath 'com.google.gms:google-services:1.4.0-beta3'

To manifest.xml:

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
...
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
Was this page helpful?
0 / 5 - 0 ratings