2

So I'm using PushSharp to send notification in c# to my android app :

      var push = new PushBroker();
      push.RegisterGcmService(new GcmPushChannelSettings(androidKey) { });
      push.QueueNotification(
                new GcmNotification().ForDeviceRegistrationId(registrationId)
                    .WithJson("{\"alert\":\"" + PushMessageFormater.FormatMessage(ncRuleResult) + "\",\"badge\":7,\"sound\":\"sound.caf\"}"));

Everything works fine, notification are correctly sent.

Now, all I want to do is to detect from my MainActivity if app is open when the final user tap in a received notification.

protected void onCreate(Bundle savedInstanceState) {
    registrationGetter = new RegistrationGetter(this);
    super.onCreate(savedInstanceState);
    Intent intent = getIntent() ;

   // How to check from here if the app is actually open further to a push tap.
}

All I found in SO is that I need to put some extra variable on the Intent, but unfornately, I can't find a way to specify the Intent from PushSharp.

Thank you in advance.

Pablo Honey
  • 1,074
  • 1
  • 10
  • 23
  • are you receiving push notifications in your device ?? – Dinesh Kannan Apr 28 '15 at 09:16
  • yes I'm receiving push notifications in my device. – Pablo Honey Apr 28 '15 at 09:17
  • you have to check from a background service/ broadcast receiver for checking if the app is in background or running.. if you invoke a activity while receiving notification in receiver makes your app to come foreground.. – Dinesh Kannan Apr 28 '15 at 09:21
  • ty @user1992200, but my question was not very clear. I've added that part : "Now, all I want to do is to detect from my MainActivity if app is open when the final user tap in a received notification." – Pablo Honey Apr 28 '15 at 09:24
  • checking if the app is in foreground from main activity is pointless .. while tapping the notification you have to invoke a service to check if app is background or not.. – Dinesh Kannan Apr 28 '15 at 09:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76425/discussion-between-user1992200-and-pablo-honey). – Dinesh Kannan Apr 28 '15 at 09:36

1 Answers1

0

change pending intent to invoke service while tapping on a notification

PendingIntent pendingIntent = PendingIntent.getService(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT);

refer here to check whether the app is in foreground or not.. you have to check this from your service invoked after tapping the received notification..

Community
  • 1
  • 1
Dinesh Kannan
  • 1,255
  • 13
  • 32