Push Notification with AppCenter when the app is closed

EnricoRossiniEnricoRossini USMember ✭✭✭✭

Hi guys,
I'm implementing Push Notification in my app with AppCenter. In UWP I created a background service to receive message when the app is closed. I'm trying to do the same with Android and, later, iOS.

In Android project I created a IntentService to initialize the Push from AppCenter but it doesn't work.

[Service]
public class PushNotificationService : IntentService
{
    public override void OnCreate()
    {
       if (!AppCenter.Configured)
        {
            Push.PushNotificationReceived += (sender, e) =>
            {
                new NotificationHelpers().ShowNotification(e.Title, e.Message, e.CustomData);
            };
        }
    }

    public override IBinder OnBind(Intent intent)
    {
        return null;
    }

    [return: GeneratedEnum]
    public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
    {
        return StartCommandResult.StickyCompatibility;
    }

    protected override void OnHandleIntent(Intent intent)
    {
    }
}

What is the correct implementation for Android? Thank you

Answers

  • MommMomm USMember ✭✭✭
    edited February 9

    Have you registered the tokens, etc?

    Also, shouldn't it be AppCenter.Configured instead of !AppCenter.Configured?

  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    @Momm said:
    Have you registered the tokens, etc?

    Also, shouldn't it be AppCenter.Configured instead of !AppCenter.Configured?

    I can receive with this code a Push Notification when the app is open. I copied this code in a service as I wrote in my post but it doesn't work.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    You should not need a service to handle push notifications on Android or iOS. That's the point of them. If you configure your app correctly, the OS will display the notification and bring the app to the foreground (even if it's not running when the Push Notification arrives).

    Unless I'm missing something regarding how App Center implements push notifications (the last time I looked it used Firebase Cloud Messaging).
  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    @JamesLavery thank you for your comment. The implementation of Push Notification cross platform with AppCenter is very easy as they explain in this document. But a simple test shows that it is not working when the app is close. For this reason I created a background service. Happy to change.

  • EricBowmanEricBowman USMember ✭✭

    I'm having the same problem and I'm looking into it as well. Did you ever find a solution?

Sign In or Register to comment.