예제 #1
0
        //private NotificationManager notificationManager;

        #region ILocalNotifications implementation

        public void SendLocalNotification(string title, string description, long time)
        {
            var builder = new Notification.Builder(Application.Context)
                          .SetContentTitle(title)
                          .SetContentText(description)
                          .SetWhen(time)
                          .SetDefaults(NotificationDefaults.All)
                          .SetSmallIcon(Resource.Drawable.icon);
            var notification = builder.Build();
            var resultIntent = new Intent(Application.Context, typeof(AfazerService));

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            var stackBuilder = TaskStackBuilder.Create(Application.Context);

            stackBuilder.AddNextIntent(resultIntent);
            var resultPendingIntent =
                stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            var notificationManager =
                Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
            const int notificationId = 0;

            notificationManager?.Notify(notificationId, notification);
        }
예제 #2
0
        public override void OnReceive(Context context, Intent intent)
        {
            var resultIntent = new Intent(context, typeof(MainActivity));

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);

            var stackBuilder = TaskScheduler.Create(context);

            stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            var chk = new ChecRunning();

            if (!chk.isMyServiceRunning(typeof(BatteryService)))
            {
                Toast.MakeText(context, "Service Restarted!", ToastLength.Long).Show();
                var backgroundServiceIntent = new Intent(context, typeof(BatteryService));
                context.StartForegroundService(backgroundServiceIntent);
            }
            else
            {
                Toast.MakeText(context, "alarm tick!", ToastLength.Long).Show();
            }


            //if (!initiate)
            //{
            //    BatteryBroadcastReceiver mReceiver = new BatteryBroadcastReceiver();
            //    context.RegisterReceiver(mReceiver, new IntentFilter(Intent.ActionBatteryChanged));
            //}
        }
        public void ShowNotification(string title, string content)
        {
            CreatNotificationChannel();
            Context context     = Android.App.Application.Context;
            var     intent      = getLaucherActivity();
            var     stackBuiler = TaskStackBuilder.Create(context);

            stackBuiler.AddNextIntent(intent);
            var pendingIntent = stackBuiler.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            if (builder == null)
            {
                builder = new Notification.Builder(context, "channel_ID");
            }

            builder.SetAutoCancel(true);
            builder.SetContentTitle(title);
            builder.SetContentIntent(pendingIntent);
            builder.SetContentText(content);
            //

            builder.SetSmallIcon(Resource.Drawable.ic_vol_type_tv_dark);
            // Resource.Drawable.ic_stat_button_click;

            Notification notification = builder.Build();

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

            notificationManager.Notify(NOTIFICATION_ID, notification);
        }
예제 #4
0
        // Handler for button click events.
        private void ButtonOnClick(object sender, EventArgs eventArgs)
        {
            // Pass the current button press count value to the next activity:
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("count", count);

            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(this, typeof(SecondActivity));

            // Pass some values to SecondActivity:
            resultIntent.PutExtras(valuesForActivity);

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetAutoCancel(true)                                                             // Dismiss the notification from the notification area when the user clicks on it
                                                 .SetContentIntent(resultPendingIntent)                                           // Start up this activity when the user clicks the intent.
                                                 .SetContentTitle("Button Clicked")                                               // Set the title
                                                 .SetNumber(count)                                                                // Display the count in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_button_click)                            // This is the icon to display
                                                 .SetContentText(String.Format("The button has been clicked {0} times.", count)); // the message to display.

            // Finally, publish the notification:
            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            notificationManager.Notify(ButtonClickNotificationId, builder.Build());

            // Increment the button press count:
            count++;
        }