0

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.

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)
    {
    }
}

Also I added in the AndroidManifest.xml

<application>
    <service android:name="PushNotificationListener" />
</application>

What is the correct implementation for Android? Is there anything to add in the AndroidManifest.xml?

Enrico
  • 3,592
  • 6
  • 45
  • 102
  • Where you start the service? – Junior Jiang Feb 11 '19 at 02:14
  • The first time is when the application starts – Enrico Feb 11 '19 at 07:46
  • When application starts to start this service,the service just run once.When application is closed,service if not running nothing can happen. – Junior Jiang Feb 11 '19 at 07:54
  • What is the correct implementation then? I can't find an example. Thank you in advance – Enrico Feb 11 '19 at 07:58
  • When you start the service, you need to add a thread to ensure that your service is always running. At the same time, according to your logic, if the notification is sent regularly, the time timer is set in the thread, and the notification can be sent when the time arrives. – Junior Jiang Feb 11 '19 at 08:10
  • Have you referred to this official document?(https://learn.microsoft.com/en-us/appcenter/sdk/push/android).Here is a dicussion about Firebase (https://stackoverflow.com/questions/54366064/not-receive-fcm-notification-when-app-is-closed/54434868#54434868) . – Junior Jiang Feb 11 '19 at 08:30

0 Answers0