rdelrosario / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
179 stars 161 forks source link

Android Push: Open application Activity after the click on the notification #20

Open michalblaha opened 8 years ago

michalblaha commented 8 years ago

Rendy, is any way how to set an Activity which is called after the click on the notification? Or open the main Activity of the app? Or do you plan to add it to the code? (for ex. like here: https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/local_notifications_in_android_walkthrough/ )

rdelrosario commented 8 years ago

Right now it loads the activity in launch mode. Yes i am planning to add some code so that you can setup which activity to load, just haven't had the time to figure out the best way to do this.

jmeadecvlt commented 8 years ago

this is really important, any update on this request?

jmeadecvlt commented 8 years ago

can you review the pull request I submitted? I've tested this locally and it works as expected for us.

JohnMcAvinue commented 8 years ago

Has this been implemented now? I get the notification to the device and IPushNotificationListener.OnMessage fires with the correct payload.

I'm fairly new to Android so wondering if there's some boilerplate I can hack to respond to notifications being clicked, and directing the user to a custom Notification activity

CR4567 commented 8 years ago

+1 Any progress on this?

jmeadecvlt commented 8 years ago

Rendy updated the code a while back that allows the android payload to be accessed, @CR4567: did you grab latest and try it out?

CR4567 commented 8 years ago

thanx for the quick answer. I'm on version 1.1.7, this should be the recent one, right? Accessing the payload when the message arrives isn't a problem. But I'm trying to handle messages differently after clicking and opening the app. Did I miss this in the documentation? I couldn't find a method that is called after clicking the msg.

jmeadecvlt commented 8 years ago

apologies, I should have been more specific, yes, the library lets you access the payload once the notification was clicked. The notification should/will fire OnCreate if your app isn't running. In that method, check Intent.Extras. If extras isn't null, there should be a KeySet collection that has the values you can use to handle any downstream decisions about what to load. hth

CR4567 commented 8 years ago

hm.... weird... you're absolutely right, the onCreate fires when clicking the msg and there is also an Intent.Extras with isEmpty = false.... but I still can't find the values of the notification.

jmeadecvlt commented 8 years ago

inside OnCreate:

Bundle extras = Intent.Extras;

if (extras != null) {

    //YAY, we have message details
    foreach (var key in extras.KeySet()) {
        System.Diagnostics.Debug.WriteLine(string.Format("MainActivity::Notification::Key:{0}|Value:{1}", key, extras.Get(key)));
    }

}
CR4567 commented 8 years ago

Ah nice. that's working. Thx a lot... couldn't see the content in debug mode but seems to be a debug problem.

CR4567 commented 7 years ago

after all that time, thinking everything is fine, I found some new and weir behavior... I mixed this code with #39 to receive and react on push notifications even when app is closed. After debugging several times, for me, it looks like the onCreate method is called each time you click on a push. Makes sense and is working usually.... but after I closed the app and clicked the notification it looks like the onCreate is only used once ... when I'm clicking again on a new push only the app starts but without any further processing....

Does that make sense to anyone? Is it using a different service or thread after closing the app?

fazil1979 commented 7 years ago

Is there any update?

corte commented 7 years ago

Any updates on this? I really need this feature :(

JulianPasque commented 7 years ago

I also need this feature.

DECWebSites commented 7 years ago

Any update?

I need to open a specific screen when I click the notification on Android.

Is it already possible?

EmmanVazz commented 7 years ago

I am on version 1.2.4. You can access the message with the method @jmeadecvlt mentioned, I use this inside OnCreate in MainActivity.cs

if(!string.IsNullOrEmpty(Intent.GetStringExtra("message")))
{
   //app was started via a push notification
}