Hi. When a new PN is received on an Android device the app's icon shows a badge with "1" on it. Good so far. When I tap it to open the app I want to display the notification but I can't get the notification data because there is no event.

If I open the app by tapping the PN from the notification bar then the event is fired and the app gets the notification data. But not if the app is opened from the home or Apps screen.

I also tried the following but it returns null: pushNotification.getLaunchNotification(function(pn){console.log(pn)})

Using PhoneGap/JavaScript, how can my app get the notification data when there's a new PN and the app is opened by tapping on its icon/badge please? Thanks.

asked 11 Jul '16, 04:12
Gary_oo's gravatar image


edited 13 Jul '16, 01:57

Hello Gary,

As far as i understood your use-case, you want your app to show push notification when the application is opened. Unfortunately, Apple notification politics forbids that kind of action. iOS platform allows data transfer to the app only if push notification have been opened, this is obligatory condition.

However, there is a way to workaround this issue but it is not totally reliable and have some restrictions. You can add “content-available”:1 parameter to the “aps” dictionary in your push payload. Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, application:didReceiveRemoteNotification:fetchCompletionHandler: is called.

If you do so, there is will be a shown push and payload data transfer to the application. You only should find a way for the application to process received content, e.g. you can save the notification text when it is received, then call getLaunchNotification() (gets a payload of a notification, if the app was opened via notification, otherwise returns null) and, if it returns null, check if there is any saved notification and draw an alert with a this content if there is one; then clear saved data to prevent further notification creation.

Please take a note that workaround mentioned above will not work if notification payload will not be passed to an application, e.g. when it is terminated, so you can lose some or all of the content you transferring if it happens.

Regards, Nikita.

permanent link
answered 14 Jul '16, 13:01
novchinnikov's gravatar image


Hi Nikita. Thank you for taking the time to explain. I'm actually developing the Android version first. I will use your iOS solution in 2 weeks time. Is there a solution for Android please? Does Android have the equivalent to {“content-available”:1} or is there a simpler solution because Google are more chilled than Apple? ;-)

(14 Jul '16, 13:24) Gary_oo Gary_oo's gravatar image


Talking about Android platform.

You could use onPushReceived, notification delivery callback. Its called every time application receives remote or local notification. Also, you should make your custom notificationFactory to alert application through the onPushReceived callback that push was received. Use the same logic, that was described in iOS example above, i.e check if app is opened with notification or not, using getLaunchNotification. Please take note that Notification Center should be cleared if push notification was not opened, but its content was already used.

Regards, Nikita.

permanent link
answered 15 Jul '16, 12:22
novchinnikov's gravatar image


edited 15 Jul '16, 12:24

Thank you again, Nikita. Are there JavaScript equivalents to onPushReceived or creating a custom notificationFactory? I'm using PhoneGap so the methods are limited to the plugin provided.

(15 Jul '16, 13:57) Gary_oo Gary_oo's gravatar image

Gary, as far as i know there is no a way to do this on PhoneGap. Such functionality is available only in the native.

(20 Jul '16, 10:31) novchinnikov novchinnikov's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 11 Jul '16, 04:12

question was seen: 1,249 times

last updated: 11 Sep '17, 19:57