OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.56k stars 373 forks source link

Unable to make android notifications appear as banner #164

Closed junshengpierre closed 4 years ago

junshengpierre commented 7 years ago

Hi,

I am trying to get android notifications to appear as a banner. I have tried inFocusDisplaying(2) but it only showed up in the notification drawer whether the app was in focus or not.

I was able to get iOS notifications to appear as a banner and show up in the notification drawer with kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayTypeNotification regardless of app focus.

Is there a config to allow banner notifications on android with RN?

react-native: 0.39.2 react-native-onesignal: 2.0.0 device: Samsung Galaxy S6 Android 6.0.1

OneSignal.inFocusDisplaying(2)
OneSignal.configure({...})
avishayil commented 7 years ago

Hi @junshengpierre , By saying "as a banner", what exactly you mean? What you are describing here is the normal behavior, I think. Can you elaborate more on this / upload a screenshot with the expected behavior? Thanks!

junshengpierre commented 7 years ago

Hi @avishayil,

With inFocusDisplaying(2) on android, when a notification is received on android, it shows up as an icon on the extreme left corner of the status bar and in the notification shade.

screen shot 2017-01-26 at 10 50 33 am

I was trying to make the notifications appear as a banner as well when the app is not in focus like this:

screen shot 2017-01-26 at 11 09 06 am

Is this possible with react-native-onesignal? Thank you.

jkasten2 commented 7 years ago

@junshengpierre ~To get a head-up notification like this you need to set the priority of the notification to 10. This can be done with the OneSignal create notification REST API call noted below. https://documentation.onesignal.com/reference#section-delivery~ Update You must create a notification category / channel to change the display priority of the notification to show the notification as a pop up banner. See the following page on setting one up and using it. https://documentation.onesignal.com/docs/android-notification-categories

junshengpierre commented 7 years ago

@jkasten2 Alright, I'll go ahead and do that. Thank you!

kelset commented 7 years ago

Hey @jkasten2 I tried going for your hint by posting to the OneSignal REST API (via RoR) with this params:

        params = {"app_id" => ENV["ONE_SIGNAL_APP_ID"],
                  "headings" => {"en" => title},
                  "contents" => {"en" => text},
                  "priority" => 10,
                  "filters" => [ {"field": "tag", "key": "server_uid", "relation": "=", "value": send_to} ]
                }

but it doesn't create a head-up notification, in my tests. I've been using an Android 6.0 real device, RN 0.38 and react-native-onesignal 1.2.3.

Is it somewhat related to the config param enableInAppAlertNotification? Does it have to be set to false?

jkasten2 commented 7 years ago

@kelset You will need to use the latest 3.0.1 react-native-onesignal SDK. This is required since the feature was added in a recent Android Native SDK update. https://github.com/OneSignal/OneSignal-Android-SDK/releases/tag/3.4.0

kelset commented 7 years ago

So it won't work even in version 2.0?

Noitidart commented 6 years ago

I'm having same issue, i set priority to high as well. How did you guys fix this?

cgilboy commented 4 years ago

@jkasten2 Per your comment here https://github.com/OneSignal/OneSignal-Android-SDK/issues/10, it looks like no client-side intervention is needed to raise the notification priority to 10 when the rest API sets it to 10. Is this true for the react-native library as well?

I can't get this to work at the moment with v3.3.2 of the RN libraary. When I examine the notification that is delivered, I see priority: 6 in my react-native client, despite sending priority: 10 via the rest api.

jorbs commented 4 years ago

Hi. Same issue here. @cgilboy did you have any luck on this?

cgilboy commented 4 years ago

@jorbs Unfortunately not. I had to move on to other priorities. Please do ping back if you find a solution!

rgomezp commented 4 years ago

@cgilboy , Please update to the latest version of the SDK as you're on a very old version. What is the response from the OneSignal REST API?

jorbs commented 4 years ago

I was able to get it using a channel.

iacocesar commented 4 years ago

same issue

jkasten2 commented 4 years ago

@IacoCesar You must create a notification category / channel to change the display priority of the notification to show the notification as a pop up banner. See the following page on setting one up and using it. https://documentation.onesignal.com/docs/android-notification-categories

YinhaoHe commented 3 years ago

Hi there, do you guys find a way to make it happen?