protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Bootstrap.Begin(() => new DeviceInstallationService());

            if (DeviceInstallationService.NotificationsSupported)
            {
                FirebaseInstanceId.GetInstance(Firebase.FirebaseApp.Instance)
                .GetInstanceId()
                .AddOnSuccessListener(this);
            }

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);

            LoadApplication(new App());

            CreateNotificationChannel();

            if (!ShortcutBadger.IsBadgeCounterSupported(this))
            {
                Console.WriteLine("Pay attention: badge counter not supported");
            }
        }
        private void RemoveBadgeCounterOnOlderPlatforms()
        {
            bool isLowerVersion          = Build.VERSION.SdkInt < BuildVersionCodes.O;
            bool isBadgeCounterSupported = ShortcutBadger.IsBadgeCounterSupported(ApplicationContext);

            // Use Plugin for badges on older platforms that support them
            if (isLowerVersion && isBadgeCounterSupported)
            {
                ShortcutBadger.RemoveCount(ApplicationContext);
            }
        }
示例#3
0
        public override void OnCreate()
        {
            base.OnCreate();

            if (ShortcutBadger.IsBadgeCounterSupported(this))
            {
                if (MainActivity.isActivityActive)
                {
                    badgeCount = 0;
                }
                else
                {
                    badgeCount += 1;
                }

                ShortcutBadger.ApplyCount(this, badgeCount);
            }
        }
        public Notification CreateNotification(NotificationViewModel notificationViewModel)
        {
            PendingIntent resultPendingIntent = InitResultIntentBasingOnViewModel(notificationViewModel);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationContext, _channelId)
                                                 .SetAutoCancel(true)                          // Dismiss the notification from the notification area when the user clicks on it
                                                 .SetContentTitle(notificationViewModel.Title) // Set the title
                                                 .SetContentText(notificationViewModel.Body)   // the message to display.
                                                 .SetContentIntent(resultPendingIntent)        // Start up this activity when the user clicks the intent.
                                                 .SetVibrate(null)
                                                 .SetSound(null)
                                                 .SetNumber(1)
                                                 .SetCategory(NotificationCompat.CategoryMessage)
                                                 .SetOnlyAlertOnce(true);

            // This is the icon to display
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                builder.SetColor(Resource.Color.colorPrimary);
            }

            builder.SetSmallIcon(Resource.Drawable.ic_notification);

            Notification notification = builder.Build();

            bool isLowerVersion          = Build.VERSION.SdkInt < BuildVersionCodes.O;
            bool isBadgeCounterSupported = ShortcutBadger.IsBadgeCounterSupported(NotificationContext);
            bool isMessage = notificationViewModel.Type == NotificationsEnum.NewMessageReceived;
            bool areNotificationsEnabled = NotificationManagerCompat.From(NotificationContext).AreNotificationsEnabled();

            // Use Plugin for badges on older platforms that support them
            if (isLowerVersion &&
                isBadgeCounterSupported &&
                isMessage &&
                areNotificationsEnabled)
            {
                ShortcutBadger.ApplyNotification(NotificationContext, notification, 1);
            }

            return(notification);
        }