Forum Xamarin.Forms

Android: Local notifications stop working when I update my app.

cmw9706cmw9706 Member ✭✭

I have an app that uses local notifications. I have a version x.1, x.2, and x.3.

If I setup notifications in my app (using AlarmManager and BroadcastReciever), they work. When I upgrade from x.1 => x.2, the notifications carry over no problem. However when I upgrade from x.2 => x.3, the notifications set up in the previous version (weather its x.1 or x.2), stop firing. That is, my BroadcastReciever.OnRecieve() stops getting hit.

The only change between the versions is I introduced a a new channel for persistent notifications that I register whenever my app starts up, but I wouldn't think this is causing any issues. I am not doing any intent filtering or registering of my broadcast receiver anywhere except for in the intent of the alarm itself?

I have been banging my head against this for days and I didn't include code because I cannot share it, but I am pretty much doing this the standard way you would for local notifications. Just curious if anyone had any thoughts?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    The only change between the versions is I introduced a a new channel for persistent notifications

    What is the version of the device that you test the code? Channel was introduced in Android 8.0 and is not available on older versions of Android.

    Please detect the version of the device:

    void CreateNotificationChannel()
    {
        if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        {
            // Notification channels are new in API 26 (and not a part of the
            // support library). There is no need to create a notification 
            // channel on older versions of Android.
            return;
        }
    
        var channel = new NotificationChannel(CHANNEL_ID, "FCM Notifications", NotificationImportance.Default)
        {
            Description = "Firebase Cloud Messages appear in this channel"
        };
    
        var notificationManager = (NotificationManager)GetSystemService(NotificationService);
        notificationManager.CreateNotificationChannel(channel);
    }
    

    Similar issue:
    https://stackoverflow.com/questions/54343866/push-notifications-not-working-in-xamarin-android

  • cmw9706cmw9706 Member ✭✭

    We already account for this ^ any other thoughts?

  • JarvanJarvan Member, Xamarin Team Xamurai

    A notification channel requires the following three pieces of information:

    • An ID string that is unique to the package that will identify the channel.
    • The name of the channel that will be displayed to the user. The name must be between one and 40 characters.

    Tutorial:
    https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/notifications/local-notifications#creating-a-notification-channel

    How did you add the notification channel? Could you post the related code?

Sign In or Register to comment.