Forum Cross Platform with Xamarin

Emulate iOS push notification functionality on Android

I built a mobile application using the Xamarin Platform and and Xamarin.Forms for Android and iOS devices. One of the requirements was to display a push notification that is sent out on a fixed schedule.

This functionality works great on the iOS platform. It does not display the push notifications on the Android platform unless the application is running either in the foreground or background on the target device. It will not handle the push notification even when the application is opened after the scheduled delivery of the notification to the application.

I used the following tutorial to set up push notifications using Xamarin.Android and Google Cloud Messaging:

What do I need do to configure my application to handle push notifications on Android when it is not running on device?


  • GuillermoGutierrezGuillermoGutierrez ESMember ✭✭✭

    On iOS the operating system receives the notification and if the application is not running, it has no clue that a notification has arrived unless this notification is tapped.

    On Android you have an activity that will receive the notification directly even if your application (main activity) is not running. You can do whatever you want, usually show a notification in the notification center.

    Maybe you're not doing anything with the notification?

    Take a look at TwinPush Android SDK, maybe you can reuse some of the functionality of displaying the notification.

    The interesting code is in the twinpush.sdk.notifications package.

  • MichaelKniskernMichaelKniskern USUniversity ✭✭

    @GuillermoGutierrez My application is handling the push notification and displaying it notification center when it is running in the foreground or background. It does not handle the notification when the application is closed/force-stopped.

    I spoke with Xamarin Support and after Android 3.1+, force stopped apps no longer get restarted by C2DM by default. You need to include this FLAG_INCLUDE_STOPPED_PACKAGES. They reviewed my code and told me I placed the activity flag in the correct location:

    public class WellnessGCMBroadcastRecevier : BroadcastReceiver
            const string _Tag = "PushHandlerBroadcaseReceiver";
            public override void OnReceive(Context context, Intent intent)
                WellnessIntentService.RunIntentInService(context, intent);
                SetResult(Result.Ok, null, null);

    But my application is still not handling the push notification when it is closed.

Sign In or Register to comment.