示例#1
0
        private void PushNotifications(Context context, string title, string text)
        {
            // Create PendingIntent
            Intent map_intent = new Intent(context, typeof(MainActivity2));

            PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, map_intent,
                                                                          PendingIntentFlags.UpdateCurrent);

            //Create Notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
                                                 .SetSmallIcon(Resource.Mipmap.ic_launcher)
                                                 .SetContentTitle(title)
                                                 .SetContentText(text)
                                                 .SetAutoCancel(true)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone))
                                                 .SetVibrate(new long[] { 1000, 1000 })
                                                 .SetContentIntent(resultPendingIntent);

            //Show Notification
            Notification notification = builder.Build();
            NotificationManagerCompat notificationManager = NotificationManagerCompat.From(context);
            var str = notificationManager.AreNotificationsEnabled();

            //NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
            notificationManager.Notify(NOTIFY_ID, notification);
        }
        public void ConfigurarNotificacion()
        {
            Android.Content.PM.Permission permiso_noty = contextApp.CheckSelfPermission(Manifest.Permission.BindNotificationListenerService);
            //permiso_noty == Permission.Denied ||

            NotificationManagerCompat manager = NotificationManagerCompat.From(contextApp);
            var IsAllowed = manager.AreNotificationsEnabled();



            if (IsAllowed)
            {
                Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
                contextApp.StartActivity(intent);
            }
        }