Exemplo n.º 1
0
        void CreateNoteChannel()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                // Note channels only required for API 26+
                return;
            }

            var channelName = Resources.GetString(Resource.String.channel_name);
            var channelDesc = GetString(Resource.String.channel_description);
            var channelID   = GetString(Resource.String.channel_ID);
            var channel     = new NotificationChannel(channelID, channelName, NotificationImportance.Default)
            {
                Description = channelDesc
            };

            var notificationsManager = (NotificationManager)GetSystemService(NotificationService);

            notificationsManager.CreateNotificationChannel(channel);
        }
Exemplo n.º 2
0
        public override void OnCreate()
        {
            base.OnCreate();
            _notificationManager = (NotificationManager)GetSystemService(NotificationService);

            if (_useNotificationChannel)
            {
                var notificationChannel = new NotificationChannel(CHANNEL_ID, "Private Messenger Notification Channel", NotificationImportance.Default)
                {
                    Description = "Private Messenger Messages",
                    LightColor  = LightColour
                };

                notificationChannel.EnableLights(true);
                notificationChannel.EnableVibration(true);
                notificationChannel.SetVibrationPattern(VibrationPattern);
                notificationChannel.SetSound(Ringtone, null);
                _notificationManager.CreateNotificationChannel(notificationChannel);
            }
        }
Exemplo n.º 3
0
        private void CreateNotificationChannel()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return;
            }

            var name        = "MyApplication";
            var description = "MyApplicationDescription";
            var channel     =
                new NotificationChannel(CHANNEL_ID, name, NotificationImportance.Default)
            {
                Description = description
            };

            channel.EnableVibration(true);
            channel.LockscreenVisibility = NotificationVisibility.Public;

            notificationManager.CreateNotificationChannel(channel);
        }
Exemplo n.º 4
0
        public static void Init()
        {
#if (!DEBUG)
            AudioManager audioManager = (AudioManager)Application.Context.GetSystemService(Context.AudioService);
            audioManager.SetStreamVolume(Stream.Music, audioManager.GetStreamMaxVolume(Stream.Music), VolumeNotificationFlags.AllowRingerModes);
#endif
            mNotifyManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);
            mBuilder       = new NotificationCompat.Builder(Application.Context, "2")
                             .SetContentTitle("下载进度")
                             .SetProgress(100, 0, false)
                             .SetSmallIcon(17301634);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                Intent        notificationIntent        = new Intent(Application.Context, Application.Context.Class);
                PendingIntent notificationPendingIntent = PendingIntent.GetActivity(Application.Context, 1, notificationIntent, PendingIntentFlags.UpdateCurrent);
                mBuilder.SetContentIntent(notificationPendingIntent);
                NotificationChannel mChannel = new NotificationChannel("2", "haha", Android.App.NotificationImportance.Low);
                mNotifyManager.CreateNotificationChannel(mChannel);
            }
        }
        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,
                                                  "InterView",
                                                  NotificationImportance.Default);

            channel.EnableLights(true);
            channel.EnableVibration(true);
            var notificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);

            notificationManager.CreateNotificationChannel(channel);
        }
        private void CreateChannel()
        {
            string channelName                = NotificationContext.Resources.GetString(Resource.String.channel_name);
            string channelDescription         = NotificationContext.Resources.GetString(Resource.String.channel_description);
            NotificationImportance importance = NotificationImportance.High;

            if (_channel == null)
            {
                _channel = new NotificationChannel(_channelId, channelName, importance)
                {
                    Description = channelDescription
                };

                _channel.SetShowBadge(true);

                NotificationManager notificationManager =
                    (NotificationManager)NotificationContext.GetSystemService(Context.NotificationService);
                notificationManager?.CreateNotificationChannel(_channel);
            }
        }
Exemplo n.º 7
0
        //Create a notification channel (android thing)
        private void CreateNotificationChannel()
        {
            manager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelNameJava = new Java.Lang.String(channelName);
                var channel         = new NotificationChannel(channelId, channelNameJava, NotificationImportance.High)
                {
                    Description          = channelDescription,
                    LockscreenVisibility = NotificationVisibility.Public,
                };
                channel.EnableLights(true);
                channel.EnableVibration(true);
                channel.LightColor = NOTIFICATION_COLOR;
                manager.CreateNotificationChannel(channel);
            }

            channelInitialized = true;
        }
        private void SetNotificationChanel(string chanelName, string chanelDescription)
        {
            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 channelName        = chanelName;
            var channelDescription = chanelDescription;

            NotificationChannel = new NotificationChannel(chanelName, channelName, NotificationImportance.Default)
            {
                Description = channelDescription
            };

            _notificationManager.CreateNotificationChannel(NotificationChannel);
        }
Exemplo n.º 9
0
        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.High)
            {
                Description = "Firebase Cloud Messages appear in this channel"
            };

            channel.EnableVibration(true);
            channel.EnableLights(true);
            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(channel);
        }
Exemplo n.º 10
0
        public 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(FirebaseService.CHANNEL_ID, FirebaseService.name, NotificationImportance.High)
            {
                Description = "Azure test channel"
            };
            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(channel);

            //DankersNotifications.Droid.MyFirebaseIDInstance firebaseService = new MyFirebaseIDInstance();
            //firebaseService.OnTokenRefresh();
        }
Exemplo n.º 11
0
        protected override void OnHandleIntent(Intent intent)
        {
            if (OreoApis.AreAvailable)
            {
                var notificationManager = GetSystemService(NotificationService) as NotificationManager;
                var channel             = new NotificationChannel(DefaultChannelId, DefaultChannelName, NotificationImportance.Low);
                channel.Description = DefaultChannelDescription;
                channel.EnableVibration(false);
                channel.SetVibrationPattern(NoNotificationVibrationPattern);
                notificationManager.CreateNotificationChannel(channel);
            }

            var notificationBuilder = new NotificationCompat.Builder(this, DefaultChannelId);

            notificationBuilder.SetVibrate(NoNotificationVibrationPattern);

            StartForeground(WidgetForegroundServiceJobId, notificationBuilder.Build());

            onHandleIntentAsync(intent);
        }
Exemplo n.º 12
0
        private void CreateChanelIfNeeded()
        {
            if (_chanelId != null)
            {
                return;
            }
            _chanelId = Guid.NewGuid().ToString();
            string chanelName          = "SocialLadder";
            var    notificationManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                // Support for Android Oreo: Notification Channels
                NotificationChannel channel = new NotificationChannel(
                    _chanelId,
                    chanelName,
                    Android.App.NotificationImportance.Default);
                notificationManager.CreateNotificationChannel(channel);
            }
        }
Exemplo n.º 13
0
        public void CreateNotificationChannel()
        {
            var activity = (Droid.MainActivity)Forms.Context;

            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return;
            }

            var channelName        = "DigiCode Push";        // Resources.GetString(Resource.String.channel_name);
            var channelDescription = "DigiCode Push Chanel"; // GetString(Resource.String.channel_description);
            var channel            = new NotificationChannel(this.channel_id, channelName, NotificationImportance.Default)
            {
                Description = channelDescription
            };

            var notificationManager = (NotificationManager)activity.GetSystemService(Context.NotificationService);

            notificationManager.CreateNotificationChannel(channel);
        }
        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, "Notification channel", NotificationImportance.Default)
            {
                Description = "channelDescription"
            };

            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(channel);
        }
        void CreateNotificationChannel()
        {
            manager = (NotificationManager)AndroidApp.Context.GetSystemService(AndroidApp.NotificationService);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelNameJava = new Java.Lang.String(channelName);
                var channel         = new NotificationChannel(channelId, channelNameJava, NotificationImportance.Default)
                {
                    Description = channelDescription
                };
                manager.CreateNotificationChannel(channel);
            }
            else
            {
                return;
            }

            channelInitialized = true;
        }
 private void CreateNotificationChannel()
 {
     try
     {
         if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
         {
             var channelName        = "YourChannel";
             var ChannelDescription = "Channel for notification";
             var channel            = new NotificationChannel("local_notification", channelName, NotificationImportance.Default)
             {
                 Description = ChannelDescription
             };
             var cNotificationManager = (NotificationManager)GetSystemService(NotificationService);
             cNotificationManager.CreateNotificationChannel(channel);
         }
     }
     catch (Exception Exp)
     {
     }
 }
        /// <summary>
        /// 创建通知渠道 >= Android O
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="notificationChannelType"></param>
        /// <returns></returns>
        protected NotificationChannel CreateNotificationChannel(NotificationManagerCompat manager,
                                                                TNotificationChannelType notificationChannelType)
        {
            var channelId           = GetChannelId(notificationChannelType);
            var name                = GetName(notificationChannelType);
            var description         = GetDescription(notificationChannelType);
            var level               = GetNotificationImportance(GetImportanceLevel(notificationChannelType));
            var notificationChannel = manager.GetNotificationChannel(channelId);

            if (notificationChannel == null)
            {
                notificationChannel = new NotificationChannel(channelId, name, level)
                {
                    Description = description,
                };
                CreateNotificationChannel(notificationChannelType, notificationChannel);
                manager.CreateNotificationChannel(notificationChannel);
            }
            return(notificationChannel);
        }
Exemplo n.º 18
0
        //Notification을 위한 채널 등록
        private void CreateNotificationChannel()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return;
            }

            var channelName        = Resources.GetString(Resource.String.channel_name);
            var channelDescription = GetString(Resource.String.channel_description);
            var channelID          = GetString(Resource.String.channel_Id);

            var channel = new NotificationChannel(channelID, channelName, NotificationImportance.Default);

            channel.Description = channelDescription;
            channel.Importance  = NotificationImportance.Max;

            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(channel);
        }
        private void DispatchFirebaseNotification(string title, string content)
        {
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                                                                              NOTIFICATION_CHANNEL_NAME, NotificationImportance.Max);

            notificationChannel.EnableLights(true);

            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            notificationManager.CreateNotificationChannel(notificationChannel);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
                                                 .SetSmallIcon(Resource.Drawable.IcPopupReminder)
                                                 .SetPriority(NotificationCompat.PriorityDefault)
                                                 .SetContentTitle(title)
                                                 .SetContentText(content);

            NotificationManagerCompat.From(this)
            .Notify(1000, builder.Build());
        }
    public NotificationChannel CreateChannel()
    {
        var channel = new NotificationChannel()
        {
            Type        = "email",
            DisplayName = "Email joe.",
            Description = "AlertTest.cs",
            Labels      = { { "email_address", "*****@*****.**" } },
            UserLabels  =
            {
                { "role",     "operations"               },
                { "level",    "5"                        },
                { "office",   "california_westcoast_usa" },
                { "division", "fulfillment"              }
            }
        };

        return(NotificationChannelClient.CreateNotificationChannel(
                   new ProjectName(ProjectId), channel));
    }
Exemplo n.º 21
0
 /**
  * For API level above or equalt o 26, Separate notification
  */
 private void CreateNotificationChannel()
 {
     if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
     {
         NotificationManager nm = (NotificationManager)GetSystemService(NotificationService);
         if (nm == null)
         {
             Logger.E("Failed to fetch NotificationManager from context.");
             return;
         }
         string channelId            = "kakao_push_channel";
         string channelName          = "Kakao SDK Push";
         NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationImportance.Default);
         channel.EnableLights(true);
         channel.LightColor = Color.Red;
         channel.EnableVibration(true);
         nm.CreateNotificationChannel(channel);
         Logger.D("successfully created a notification channel.");
     }
 }
Exemplo n.º 22
0
        public CustomNavigationNotification(Context applicationContext)
        {
            notificationManager = (NotificationManager)applicationContext.GetSystemService(Context.NotificationService);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                NotificationChannel notificationChannel = new NotificationChannel(
                    CUSTOM_CHANNEL_ID, CUSTOM_CHANNEL_NAME, NotificationImportance.Low
                    );
                notificationManager.CreateNotificationChannel(notificationChannel);
            }

            customNotificationBuilder = new NotificationCompat.Builder(applicationContext, CUSTOM_CHANNEL_ID)
                                        .SetSmallIcon(Resource.Drawable.ic_navigation)
                                        .SetContentTitle("Custom Navigation Notification")
                                        .SetContentText("Display your own content here!")
                                        .SetContentIntent(CreatePendingStopIntent(applicationContext));

            customNotification = customNotificationBuilder.Build();
        }
Exemplo n.º 23
0
        private Notification CreateNotification()
        {
            #region Create Channel
            string channelId          = "foreground";
            string channelName        = "foreground";
            string channelDescription = "The foreground channel for notifications";
            int    _pendingIntentId   = 1;

            NotificationManager _notificationManager;
            _notificationManager = (NotificationManager)Android.App.Application.Context.GetSystemService(Android.App.Application.NotificationService);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelNameJava = new Java.Lang.String(channelName);
                var channel         = new NotificationChannel(channelId, channelNameJava, NotificationImportance.Low)
                {
                    Description = channelDescription,
                };
                channel.EnableVibration(false);
                _notificationManager.CreateNotificationChannel(channel);
            }
            #endregion

            #region Create Notification
            Intent foregroundNotificationIntent = new Intent(Android.App.Application.Context, typeof(MainActivity));

            PendingIntent pendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, _pendingIntentId, foregroundNotificationIntent, PendingIntentFlags.OneShot);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(Android.App.Application.Context, channelId)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("ForegroundServiceApp")
                                                 .SetContentText("Foreground service started")
                                                 .SetOngoing(true)
                                                 .SetColor(ActivityCompat.GetColor(Android.App.Application.Context, Resource.Color.colorAccent))
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(Android.App.Application.Context.Resources, Resource.Drawable.xamagonBlue))
                                                 .SetSmallIcon(Resource.Drawable.xamagonBlue);

            var notification = builder.Build();
            #endregion

            return(notification);
        }
Exemplo n.º 24
0
        private void SendNotification(string messageBody, IDictionary <string, string> data)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            if (data != null)
            {
                foreach (var key in data.Keys)
                {
                    intent.PutExtra(key, data[key]);
                }
            }

            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            string channelId = "fcm_default_channel";

            Android.Net.Uri defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var             notificationBuilder = new NotificationCompat.Builder(this, channelId)
                                                  .SetSmallIcon(Resource.Drawable.notification_icon)
                                                  .SetStyle(new NotificationCompat.BigTextStyle()
                                                            .BigText(messageBody))
                                                  .SetColor(Color.Black.ToArgb())
                                                  .SetContentText(messageBody)
                                                  .SetAutoCancel(true)
                                                  .SetSound(defaultSoundUri)
                                                  .SetContentIntent(pendingIntent);

            var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            if (Build.VERSION.SdkInt >= Build.VERSION_CODES.O)
            {
                NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title", NotificationManager.ImportanceDefault);
                notificationManager.CreateNotificationChannel(channel);
            }

            Random random  = new Random();
            int    notifId = random.Next(9999 - 1000) + 1000;

            notificationManager.Notify(notifId, notificationBuilder.Build());
        }
Exemplo n.º 25
0
        /**
         * Create and show a simple notification containing the received FCM message.
         */
        void SendNotification(string messageBody)
        {
            Android.Util.Log.Debug(TAG, "Location: SendNotification*************");
            var notificationManager = NotificationManager.FromContext(this);

            //Check if notification channel exists and if not create one
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                NotificationChannel notificationChannel = notificationManager.GetNotificationChannel(NOTIFICATION_CHANNEL_ID);
                if (notificationChannel == null)
                {
                    notificationChannel            = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_DESCRIPTION, NotificationImportance.Default);
                    notificationChannel.LightColor = (int)ConsoleColor.Green; //Set if it is necesssary
                    notificationChannel.EnableVibration(true);                //Set if it is necesssary
                    //notificationChannel.SetSound(defaultSoundUri, AudioAttributes.);
                    notificationManager.CreateNotificationChannel(notificationChannel);
                }
            }

            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0 /* Request code */, intent, PendingIntentFlags.OneShot);

            //builder.setContentTitle() // required
            //        .setSmallIcon() // required
            //        .setContentText() // required
            //        .setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this)


            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.icon)
                                      .SetContentTitle("Wootrix Message")
                                      .SetContentText(messageBody)
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent)
                                      .SetChannelId(NOTIFICATION_CHANNEL_ID);

            notificationManager.Notify(NOTIFICATION_ID /* ID of notification */, notificationBuilder.Build());
        }
Exemplo n.º 26
0
        /// <summary>
        /// Show a local notification
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        /// <param name="id">Id of the notification</param>
        public void Show(string title, string body, int id = 0)
        {
            if (!BuilderDic.ContainsKey(id))
            {
                BuilderDic[id] = new Notification.Builder(Application.Context);
                BuilderDic[id].SetAutoCancel(true);
                BuilderDic[id].SetOnlyAlertOnce(true);
            }
            var builder = BuilderDic[id];

            builder.SetContentTitle(title);
            builder.SetContentText(body);

            if (NotificationIconId != 0)
            {
                builder.SetSmallIcon(NotificationIconId);
            }
            else
            {
                builder.SetSmallIcon(Android.Resource.Drawable.AlertDarkFrame);
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelId = $"{_packageName}.general";
                var channel   = new NotificationChannel(channelId, "General", NotificationImportance.Default);

                _manager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);
            }

            var resultIntent        = GetLauncherActivity();
            var resultPendingIntent = PendingIntent.GetActivity(Application.Context, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            var notificaton = builder.Build();

            _manager.Notify(id, notificaton);
        }
Exemplo n.º 27
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message         = intent.GetStringExtra("message");
            var title           = intent.GetStringExtra("title");
            var notification_id = intent.GetStringExtra("notify_id");
            int unique_id       = 0;

            int.TryParse(notification_id.ToString(), out unique_id);

            var notIntent     = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, unique_id, notIntent, PendingIntentFlags.CancelCurrent);

            var channel = new NotificationChannel(CHANNEL, "Notification", NotificationImportance.Default)
            {
                LockscreenVisibility = NotificationVisibility.Public
            };

            int resourceId;

            resourceId = Resource.Drawable.local_rem_n;

            //Generate a notification with just short text and small icon
            var builder = new NotificationCompat.Builder(context)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.local_rem_n)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetChannelId(CHANNEL)
                          .SetAutoCancel(true);
            //.SetVisibility(NotificationVisibility.Public);


            NotificationManager manager = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService);

            manager.CreateNotificationChannel(channel);

            var notification = builder.Build();

            manager.Notify(unique_id, notification);
        }
Exemplo n.º 28
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.notificationlistener_submenu);

            text = FindViewById <TextView>(Resource.Id.textViewNL);

            Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");

            StartActivity(intent);
            NotificationListener nl = new NotificationListener();

            StartService(new Intent(this, typeof(NotificationListener)));

            //Notification:
            var channel = new NotificationChannel(CHANNEL_ID, "powiadomienia", NotificationImportance.Default)
            {
                Description = "opis"
            };
            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(channel);


            Button createNotificationButton = FindViewById <Button>(Resource.Id.buttonCreateNotification);

            createNotificationButton.Click += (o, r) =>
            {
                var builder = new Notification.Builder(this, CHANNEL_ID)
                              .SetAutoCancel(true)
                              .SetNumber(i)
                              .SetContentTitle("My notification")
                              .SetSmallIcon(Resource.Drawable.abc_ic_star_black_16dp)
                              .SetContentText("Test notification");

                var notificationManager2 = NotificationManagerCompat.From(this);
                notificationManager2.Notify(1000, builder.Build());
                i++;
                StatusBarNotification[] sbn = nl.GetActiveNotifications();
            };
        }
Exemplo n.º 29
0
 private void CreateNotification()/* Notification*/
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
     {
         //NotificationManager manager =
         //(NotificationManager) AndroidApp.Context.GetSystemService(AndroidApp.NotificationService);
         var channelNameJava = new Java.Lang.String(channelName);
         var channel         = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelNameJava, NotificationImportance.Max)
         {
             Description          = channelDescription,
             LightColor           = 1,
             LockscreenVisibility = NotificationVisibility.Public
         };
         //manager.CreateNotificationChannel(channel);
         notificationManager.CreateNotificationChannel(channel);
         notification = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
                        .SetContentTitle("Suleymaniye Vakfi Takvimi")
                        .SetContentText(GetFormattedRemainingTime())
                        .SetSmallIcon(Resource.Drawable.app_logo)
                        .SetContentIntent(BuildIntentToShowMainActivity())
                        .SetOngoing(true)
                        .SetCategory(NotificationCompat.CategoryService)
                        .SetOnlyAlertOnce(true)
                        //.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate)
                        .Build();
     }
     else
     {
         notification = new Notification.Builder(this)
                        .SetContentTitle("Suleymaniye Vakfi Takvimi")
                        .SetContentText(GetFormattedRemainingTime())
                        .SetSmallIcon(Resource.Drawable.app_logo)
                        .SetContentIntent(BuildIntentToShowMainActivity())
                        .SetOngoing(true)
                        .SetCategory(NotificationCompat.CategoryService)
                        .SetOnlyAlertOnce(true)
                        //.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate)
                        .Build();
         //return notification;
     }
 }
        private void registerForService()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channel = new NotificationChannel(CHANNEL_ID, "Channel", NotificationImportance.Default)
                {
                    Description = "Rastreamento iniciado"
                };

                var notificationManager = (NotificationManager)GetSystemService(NotificationService);
                notificationManager.CreateNotificationChannel(channel);

                var notification = new Notification.Builder(this, CHANNEL_ID)
                                   .SetContentTitle("etc")
                                   .SetContentText("etc")
                                   .SetSmallIcon(Resource.Drawable.icone)
                                   .SetContentIntent(BuildIntentToShowMainActivity())
                                   .SetOngoing(true)
                                   //.AddAction(BuildRestartTimerAction())
                                   //.AddAction(BuildStopServiceAction())
                                   .Build();

                // Enlist this instance of the service as a foreground service
                StartForeground(FORSERVICE_NOTIFICATION_ID, notification);
            }
            else
            {
                var notification = new Notification.Builder(this)
                                   .SetContentTitle("RADAR FAMILY")
                                   .SetContentText("Rastreamento inicializado.")
                                   .SetSmallIcon(Resource.Drawable.icone)
                                   .SetContentIntent(BuildIntentToShowMainActivity())
                                   .SetOngoing(true)
                                   //.AddAction(BuildRestartTimerAction())
                                   //.AddAction(BuildStopServiceAction())
                                   .Build();

                // Enlist this instance of the service as a foreground service
                StartForeground(FORSERVICE_NOTIFICATION_ID, notification);
            }
        }
    private void createChannel(string accTok, string endP)
    {
        FileStream fileStream = null;
        StreamWriter streamWriter = null;
        try
        {
            string contextURL = string.Empty;
            contextURL = string.Empty + endP + "/notification/v1/channels";

            HttpWebRequest createChannelWebRequest = (HttpWebRequest)WebRequest.Create(contextURL);
            createChannelWebRequest.Headers.Add("Authorization", "Bearer " + accTok);
            createChannelWebRequest.Method = "POST";
            createChannelWebRequest.KeepAlive = true;
            createChannelWebRequest.Accept = "application/json";
            createChannelWebRequest.ContentType = "application/json";

            string payLoadString = "{\"channel\": { \"serviceName\": \"MIM\", \"notificationContentType\": \"application/json\", \"notificationVersion\": 1.0 } }" ;

            UTF8Encoding encoding = new UTF8Encoding();
            byte[] postBytes = encoding.GetBytes(payLoadString);
            createChannelWebRequest.ContentLength = postBytes.Length;

            Stream postStream = createChannelWebRequest.GetRequestStream();
            postStream.Write(postBytes, 0, postBytes.Length);
            postStream.Close();
            WebResponse createChannelWebResponse = createChannelWebRequest.GetResponse();
            using (StreamReader stream = new StreamReader(createChannelWebResponse.GetResponseStream()))
            {
                string createChannelData = stream.ReadToEnd();
                JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer();
                csGetChannelDetails deserializedJsonObj = (csGetChannelDetails)deserializeJsonObject.Deserialize(createChannelData, typeof(csGetChannelDetails));

                if (null != deserializedJsonObj)
                {
                    notificationChannelSuccessResponse = "Success : " + createChannelData ;
                    this.notificationChannel = deserializedJsonObj.channel;
                    this.notificationChannel.notificationContentType = "application/json";
                    this.notificationChannel.channelType = "http_callback";
                    this.channelCreated = true;

                    fileStream = new FileStream(Request.MapPath(this.webhooknotificationChannelFilePath), FileMode.OpenOrCreate, FileAccess.Write);
                    streamWriter = new StreamWriter(fileStream);
                    streamWriter.WriteLine(this.notificationChannel.channelId);
                    streamWriter.WriteLine(this.notificationChannel.channelType);
                    streamWriter.WriteLine(this.notificationChannel.maxEventsPerNotification);
                    streamWriter.WriteLine(this.notificationChannel.notificationContentType);

                }
                else
                {
                    notificationChannelErrorResponse = "No response from server";
                }

                stream.Close();
            }
        }
        catch (WebException we)
        {
            string errorResponse = string.Empty;
            try
            {
                using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream()))
                {
                    errorResponse = sr2.ReadToEnd();
                    sr2.Close();
                }
                notificationChannelErrorResponse = errorResponse;
            }
            catch
            {
                errorResponse = "Unable to get response";
                notificationChannelErrorResponse = errorResponse;
            }
        }
        catch (Exception ex)
        {
            notificationChannelErrorResponse = ex.Message;
            return;
        }
        finally
        {
            if (null != streamWriter)
            {
                streamWriter.Close();
            }

            if (null != fileStream)
            {
                fileStream.Close();
            }
        }

    }