Hi,

i'm developing an app using cordova and the pushwoosh service/plugin. I have a little problem on Android when a push notification arrives and the app is executing in foreground. When the push notification arrives, the application consumes the notification (it shows at the header bar for a while and then disappears) and the user doesn't notice.

Problably it's only a permission and configuration thing on AndroidManifest... how can i do to mantain the notification until the user clicks on it?

thanks in advance,

asked 30 Jun '15, 07:40
jaanguita's gravatar image

jaanguita
2114

Hello,

The instruction below is for Native Android, on Cordova you need to do the same in PushNotifications.java file.

Here is the code from the MainActivity of our Sample App:

//Push message receiver
private BroadcastReceiver mReceiver = new BasePushMessageReceiver()
{
   @Override
   protected void onMessageReceive(Intent intent)
   {
      //JSON_DATA_KEY contains JSON payload of push notification.
      doOnMessageReceive(intent.getExtras().getString(JSON_DATA_KEY));
   }
};

What you need to do is to override the receiver like this:

//Push message receiver
private BroadcastReceiver mReceiver = new BasePushMessageReceiver()
{

   @Override
   public void onReceive(Context context, Intent intent)
   {
      int id = PreferenceUtils.getMessageId(context);
      PreferenceUtils.setMessageId(context,-1);
      super.onReceive(context,intent);
      PreferenceUtils.setMessageId(context,id);
   }
   @Override
   protected void onMessageReceive(Intent intent)
   {
      //JSON_DATA_KEY contains JSON payload of push notification.
      doOnMessageReceive(intent.getExtras().getString(JSON_DATA_KEY));
   }
};

This way none of your pushes will be cancelled when the app is in foreground.

permanent link
answered 01 Jul '15, 10:12
Benedict's gravatar image

Benedict
7127

Hi,

thanks for the answer, i have been doing some tests based on the code you posted and now arrives the notification and the user can see it, because it keeps on the header. But the notification is still processed because the super.onReveice call.

Can i override the onReceive() method with no code inside? implications?

thanks!

permanent link
answered 02 Jul '15, 10:38
jaanguita's gravatar image

jaanguita
2114

Looking at the super.onReceive declaration i need to do:

  • don't cancel the messageId via notification manager
  • send the pushStat
  • don't do the onMessageReceive

how can avoid to call the super.onReceive but still sending the pushStat?

permanent link
answered 07 Jul '15, 12:09
jaanguita's gravatar image

jaanguita
2114

This topic is still not solved.

The initial solution is not correct because the notification is still processed when the notification arrives when app is in background state. If i override method OnReceive (from BroadcastReceiver), calling super.onReceive(context,intent); the notification keeps at the status bar, but internally the notification is consumed and i don't want that behavior.

permanent link
answered 05 Aug '15, 15:08
jaanguita's gravatar image

jaanguita
2114

Sorry for such a delay. Instead of the solution suggested above, could you possibly try setting the following to "false"?

< meta-data android:name="PW_BROADCAST_PUSH" android:value="true" />

This way your notifications will be accessible in the Notification Bar even if the app was in the foreground.

permanent link
answered 11 Aug '15, 14:00
Benedict's gravatar image

Benedict
7127

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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:

×446
×190
×141
×30

question asked: 30 Jun '15, 07:40

question was seen: 3,495 times

last updated: 11 Aug '15, 14:00