Пример #1
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("mensagem");
            var title   = intent.GetStringExtra("titulo");

            var notIntent     = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(context);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

            var wearableExtender = new NotificationCompat.WearableExtender()
                                   .SetBackground(BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon));

            //Generate a notification with just short text and small icon
            var builder = new NotificationCompat.Builder(context)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.icon)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true)
                          .Extend(wearableExtender);

            var notification = builder.Build();

            manager.Notify(0, notification);
        }
Пример #2
0
        public void CreateLocalNotification(string titolo, string descrizione, int id, string rifordine, int idriga)
        {
            Context             ctx = Forms.Context;
            NotificationManager nm  = (NotificationManager)ctx.GetSystemService(Context.NotificationService);


            int notId = id + 9999;
            //esecuzione dell'intent
            //Yes intent
            Intent yesReceive = new Intent( );

            yesReceive.SetAction("YES_ACTION");
            Bundle yesBundle = new Bundle();

            yesBundle.PutInt("risp", 1);//This is the value I want to pass
            yesBundle.PutInt("id", id);
            yesBundle.PutString("ordine", rifordine);
            yesBundle.PutInt("idriga", idriga);
            yesReceive.PutExtras(yesBundle);
            PendingIntent pendingIntentYes = PendingIntent.GetBroadcast(ctx, notId, yesReceive, PendingIntentFlags.CancelCurrent);
            //no intent
            Intent noReceive = new Intent();

            noReceive.SetAction("NO_ACTION");
            Bundle noBundle = new Bundle();

            noBundle.PutInt("risp", 0);//This is the value I want to pass
            noBundle.PutInt("id", id);
            noReceive.PutExtras(noBundle);
            PendingIntent pendingIntentNo = PendingIntent.GetBroadcast(ctx, notId, noReceive, PendingIntentFlags.CancelCurrent);



            Android.Content.Res.Resources res = ctx.Resources;
            Bitmap bm = BitmapFactory.DecodeResource(res, FishOnLine.Droid.Resource.Drawable.icon);

            System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
            System.Text.Encoding iso  = System.Text.Encoding.GetEncoding("ISO-8859-1");
            string msg = iso.GetString(utf8.GetBytes(descrizione));

            NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
                                                 .SetPriority(NotificationCompat.PriorityMax)
                                                 .SetAutoCancel(true)
                                                 .SetLargeIcon(Bitmap.CreateScaledBitmap(bm, 80, 80, false))
                                                 .SetSmallIcon(Resource.Drawable.IcDialogInfo)
                                                 .SetContentTitle(titolo)
                                                 .SetContentText(msg)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .SetOngoing(true)
                                                 .AddAction(Resource.Drawable.IcDelete, "Cancella", pendingIntentYes)
                                                 .AddAction(Resource.Drawable.IcMenuCloseClearCancel, "Chiudi", pendingIntentNo);
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
            bigTextStyle.SetBigContentTitle(titolo);
            bigTextStyle.BigText(descrizione);

            builder.SetStyle(bigTextStyle);


            nm.Notify(notId, builder.Build());
        }
Пример #3
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");

            var notIntent               = new Intent(context, typeof(MainActivity));
            var contentIntent           = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

            Android.Net.Uri uri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);

            var builder = new NotificationCompat.Builder(context, plan_main.CHANNEL_ID)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.Icon)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetSound(uri)
                          .SetColor(ActivityCompat.GetColor(context, Resource.Color.colorPrimaryDark));

            var notification = builder.Build();

            manager.Notify(0, notification);
        }
Пример #4
0
        public override void OnReceive(Context context, Intent intent)
        {
            string description = intent.GetStringExtra("description");
            string title       = intent.GetStringExtra("title");

            var notIntent     = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(context);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(description);

            var builder = new NotificationCompat.Builder(context)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.icon) // TODO: Add launcher image here
                          .SetContentTitle(title)
                          .SetContentText(description)
                          .SetStyle(style)
                          .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true);

            var notification = builder.Build();

            manager.Notify(0, notification);
        }
        /// <summary>
        /// Displays a notification, which opens the specified activity when clicked.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="channelId"></param>
        /// <param name="title"></param>
        /// <param name="text"></param>
        /// <param name="iconResourceId"></param>
        /// <param name="bigText"></param>
        /// <param name="priority"></param>
        /// <param name="autoCancel"></param>
        protected void ShowNotification <T>(string channelId, string title, string text, int iconResourceId, string bigText = default, NotificationImportance priority = NotificationImportance.Default, bool autoCancel = true) where T : Activity
        {
            try
            {
                var builder = new NotificationCompat.Builder(Context, channelId)
                              .SetContentTitle(title).SetContentText(text).SetAutoCancel(autoCancel).SetPriority((int)priority).SetSmallIcon(iconResourceId);

                if (!string.IsNullOrEmpty(bigText))
                {
                    using (var style = new NotificationCompat.BigTextStyle()) { builder.SetStyle(style.BigText(bigText)); }
                }

                var intent  = new Intent(Context, typeof(T));
                var pending = PendingIntent.GetActivity(Context, 0, intent, PendingIntentFlags.UpdateCurrent);
                builder.SetContentIntent(pending);

                Logging.Log(LogType.Event, $"Firing Notification with Intent; Title: {title}; Text: {text}");
                manager.Notify(1, builder.Build());
            }
            catch (System.Exception e)
            {
                Logging.Log(LogType.Exception,
                            $"Something went wrong processing the new notification. Exception message: {e.Message}; Exception Stacktrace: {e.StackTrace}");
                throw;
            }
        }
        public override void OnReceive(Context context, Intent intent)
        {
            if (RetreiveLatestReceiver.IsAvailableVersion(context))
            {
                intent.PutExtra("title", string.Format(context.Resources.GetString(Resource.String.notification_title), "WhatsApp " + RetreiveLatestReceiver.GetLatestVersion()));
                intent.PutExtra("message", string.Format(context.Resources.GetString(Resource.String.notification_description), context.Resources.GetString(Resource.String.app_name)));
                var message = intent.GetStringExtra("message");
                var title   = intent.GetStringExtra("title");

                var notIntent     = new Intent(context, typeof(MainActivity));
                var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
                var manager       = NotificationManagerCompat.From(context);

                var style      = new NotificationCompat.BigTextStyle().BigText(message);
                int resourceId = Resource.Drawable.ic_launcher;

                var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId));

                // Generate notification (short text and small icon)
                var builder = new NotificationCompat.Builder(context);
                builder.SetContentIntent(contentIntent);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetStyle(style);
                builder.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()); // When the AlarmManager will check changes?
                builder.SetAutoCancel(true);
                builder.Extend(wearableExtender);                          // Support Android Wear, yeah!

                var notification = builder.Build();
                manager.Notify(0, notification);
            }
        }
Пример #7
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message       = intent.GetStringExtra("message");
            var title         = intent.GetStringExtra("title");
            var notIntent     = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(context);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

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

            var notification = builder.Build();

            manager.Notify(0, notification);
            Log.Debug(TAG, "Alarm Manager started");
        }
		public override void OnReceive (Context context, Intent intent) {
			if (RetreiveLatestReceiver.IsAvailableVersion(context)) {
				intent.PutExtra ("title", string.Format(context.Resources.GetString(Resource.String.notification_title), "WhatsApp " + RetreiveLatestReceiver.GetLatestVersion ()));
				intent.PutExtra ("message", string.Format(context.Resources.GetString(Resource.String.notification_description), context.Resources.GetString(Resource.String.app_name)));
				var message = intent.GetStringExtra ("message");
				var title = intent.GetStringExtra ("title");

				var notIntent = new Intent (context, typeof(MainActivity));
				var contentIntent = PendingIntent.GetActivity (context, 0, notIntent, PendingIntentFlags.CancelCurrent);
				var manager = NotificationManagerCompat.From (context);

				var style = new NotificationCompat.BigTextStyle ().BigText (message);
				int resourceId = Resource.Drawable.ic_launcher;

				var wearableExtender = new NotificationCompat.WearableExtender ().SetBackground (BitmapFactory.DecodeResource (context.Resources, resourceId));

				// Generate notification (short text and small icon)
				var builder = new NotificationCompat.Builder (context);
				builder.SetContentIntent (contentIntent);
				builder.SetSmallIcon (Resource.Drawable.ic_launcher);
				builder.SetContentTitle (title);
				builder.SetContentText (message);
				builder.SetStyle (style);
				builder.SetWhen (Java.Lang.JavaSystem.CurrentTimeMillis ()); // When the AlarmManager will check changes?
				builder.SetAutoCancel (true);
				builder.Extend (wearableExtender); // Support Android Wear, yeah!

				var notification = builder.Build ();
				manager.Notify (0, notification);
			}
		}
Пример #9
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");

            var notIntent     = new Intent(context, typeof(MainActivity1));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.UpdateCurrent);
            var manager       = NotificationManagerCompat.From(context);
            var style         = new NotificationCompat.BigTextStyle();

            style.BigText(message);
            int resourceId;

            resourceId = Resource.Drawable.ic_stat_button_click;

            var wearableExtender = new NotificationCompat.WearableExtender()
                                   .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId))
            ;
            var builder = new NotificationCompat.Builder(context)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.ic_stat_button_click)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true)
                          .Extend(wearableExtender);


            var notification = builder.Build();

            manager.Notify(0, notification);
        }
Пример #10
0
        public int ScheduleNotification(string title, string message)
        {
            if (!channelInitialized)
            {
                CreateNotificationChannel();
            }

            messageId++;

            Intent intent = new Intent(AndroidApp.Context, typeof(MainActivity));

            intent.PutExtra(TitleKey, title);
            intent.PutExtra(MessageKey, message);

            PendingIntent pendingIntent = PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId, intent, PendingIntentFlags.OneShot);

            NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
            textStyle.BigText(message);
            textStyle.SetSummaryText(message);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, channelId)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle(title)
                                                 .SetContentText(message)
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources, Resource.Drawable.icon))
                                                 .SetSmallIcon(Resource.Drawable.icon)
                                                 .SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate)
                                                 .SetStyle(textStyle);

            Notification notification = builder.Build();

            manager.Notify(messageId, notification);

            return(messageId);
        }
Пример #11
0
		private void CreateNotification(Intent intent) {
			recipe = Recipe.FromBundle(intent.GetBundleExtra(Constants.ExtraRecipe));
			List<Notification> notificationPages = new List<Notification> ();

			int stepCount = recipe.RecipeSteps.Count;

			for (int i = 0; i < stepCount; i++) {
				Recipe.RecipeStep recipeStep = recipe.RecipeSteps [i];
				var style = new NotificationCompat.BigTextStyle ();
				style.BigText (recipeStep.StepText);
				style.SetBigContentTitle (String.Format (Resources.GetString (Resource.String.step_count), i + 1, stepCount));
				style.SetSummaryText ("");
				var builder = new NotificationCompat.Builder (this);
				builder.SetStyle (style);
				notificationPages.Add (builder.Build ());
			}

			var notifBuilder = new NotificationCompat.Builder(this);

			if (recipe.RecipeImage != null) {
				Bitmap recipeImage = Bitmap.CreateScaledBitmap(
					AssetUtils.LoadBitmapAsset(this, recipe.RecipeImage),
					Constants.NotificationImageWidth, Constants.NotificationImageHeight, false);
				notifBuilder.SetLargeIcon(recipeImage);
			}
			notifBuilder.SetContentTitle (recipe.TitleText);
			notifBuilder.SetContentText (recipe.SummaryText);
			notifBuilder.SetSmallIcon (Resource.Mipmap.ic_notification_recipe);

			Notification notification = notifBuilder.Extend(new NotificationCompat.WearableExtender().AddPages(notificationPages)).Build();
			notificationManager.Notify (Constants.NotificationId, notification);
		}
Пример #12
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");

            var notIntent     = new Intent(context, typeof(MainScreen));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(context);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

            int resourceId = Resource.Drawable.HappyBaby;

            var wearableExtender = new NotificationCompat.WearableExtender()
                                   .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId));

            //Generate a notification with just short text and small icon
            var builder = new NotificationCompat.Builder(context)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.HappyBaby)
                          .SetSound(Android.Net.Uri.Parse("android.resource://com.iinotification.app/" + Resource.Raw.babySound))
                          .SetContentTitle("Hey Mom")
                          .SetContentText("Here I'm :)")
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true)
                          .Extend(wearableExtender);

            var notification = builder.Build();

            manager.Notify(0, notification);
        }
Пример #13
0
		public override void OnReceive (Context context, Intent intent)
		{
			var message = intent.GetStringExtra("message");
			var title = intent.GetStringExtra("title");

			var notIntent = new Intent(context, typeof(MainScreen));
			var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
			var manager = NotificationManagerCompat.From(context);

			var style = new NotificationCompat.BigTextStyle();
			style.BigText(message);

			int resourceId = Resource.Drawable.HappyBaby;

			var wearableExtender = new NotificationCompat.WearableExtender()
				.SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId));

			//Generate a notification with just short text and small icon
			var builder = new NotificationCompat.Builder(context)
				.SetContentIntent(contentIntent)
				.SetSmallIcon(Resource.Drawable.HappyBaby)
				.SetSound(Android.Net.Uri.Parse("android.resource://com.iinotification.app/"+ Resource.Raw.babySound))
				.SetContentTitle("Hey Mom")
				.SetContentText("Here I'm :)")
				.SetStyle(style)
				.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
				.SetAutoCancel(true)
				.Extend(wearableExtender);

			var notification = builder.Build();
			manager.Notify(0, notification);
		}
Пример #14
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");

            var notIntent = new Intent(context, typeof(MainActivity));

            notIntent.AddFlags(ActivityFlags.NewTask);
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(context);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

            //Generate a notification with just short text and small icon
            var builder = new NotificationCompat.Builder(context)
                          .SetDefaults(1 | 2) // sound and vibrate
                          .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm))
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.icon)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true);
            var notification = builder.Build();

            manager.Notify(0, notification);

            // Will pull up app...
            context.StartActivity(notIntent);
            //Toast.MakeText(context, message, ToastLength.Short).Show();
        }
Пример #15
0
        //push notification for phone and android wear
        private void PushNotification(Intent intent)
        {
            var style = new NotificationCompat.BigTextStyle().BigText(durationString);

            //wearable notification
            var wearableExtender = new NotificationCompat.WearableExtender()
                                   .SetBackground(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.trucktrackbackground));

            try
            {
                // Instantiate the builder and set notification elements:
                builder.SetContentTitle(suggestString)
                .SetContentText(durationString)
                .SetSmallIcon(Resource.Drawable.trucktrackicon)
                .SetStyle(style)
                //2 for max priority
                .SetPriority(2)
                //2 for vibration
                .SetDefaults(2)
                //0x1 for sound
                .SetDefaults(0x1)
                //enable wearable extender
                .Extend(wearableExtender);

                // Build the notification:
                notification = builder.Build();

                // Publish the notification:
                const int notificationId = 0;
                notificationManager.Notify(notificationId, notification);
            }catch { }
        }
        public void Show(string title, string message)
        {
            Intent intent = new Intent(AndroidApp.Context, typeof(MainActivity));

            intent.PutExtra(TitleKey, title);
            intent.PutExtra(MessageKey, message);

            PendingIntent pendingIntent = PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId++, intent, PendingIntentFlags.UpdateCurrent);

            NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
            textStyle.BigText(message);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, channelId)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle(title)
                                                 .SetContentText(message)
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources, Resource.Drawable.NotificationLogo))
                                                 .SetStyle(textStyle)
                                                 .SetSmallIcon(Resource.Drawable.NotificationLogo)
                                                 .SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate);

            Notification notification = builder.Build();

            manager.Notify(messageId++, notification);
        }
Пример #17
0
        public override void OnReceive(Context context, Intent intent)
        {
            //  Toast.MakeText(Android.App.Application.Context, "Receiver:OnReceive", ToastLength.Long).Show();
            var message       = intent.GetStringExtra("message");
            var title         = intent.GetStringExtra("title");
            var contentIntent = PendingIntent.GetActivity(Android.App.Application.Context, 0, new Intent(Android.App.Application.Context, typeof(MainActivity)), 0);
            var manager       = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService);
            var style         = new NotificationCompat.BigTextStyle();

            style.BigText(message);

            //Generate a notification with just short text and small icon
            var builder = new NotificationCompat.Builder(Android.App.Application.Context)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.icon)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true);


            var notification = builder.Build();

            manager.Notify(0, notification);
        }
Пример #18
0
        public static void NotifyAlarmComeback()
        {
            var context = Application.Context;

            var manager = SetNotificationManager();

            string title   = "5초의 알람을 잊으신건 아니시죠..";
            string message = "5초의 법칙으로 삶을 바꾸겠다는 의지를 떠올리세요! 마포대교는 무너져도 우리의 굳건한 의지는 무너지지 않습니다!"
                             + Environment.NewLine
                             + Environment.NewLine
                             + "앱에서 5초의 알람을 설정해보세요~";
            string bigText = "5초의 법칙으로 삶을 바꾸겠다는 의지를 떠올리세요! 마포대교는 무너져도 우리의 굳건한 의지는 무너지지 않습니다!"
                             + Environment.NewLine
                             + Environment.NewLine
                             + "앱에서 5초의 알람을 설정해보세요~";

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(bigText);

            var notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
            var notification        = notificationBuilder.SetOngoing(false)
                                      .SetSmallIcon(Resource.Drawable.ic_five_seconds_mini)
                                      .SetContentTitle(title)
                                      .SetContentText(message)
                                      .SetPriority((int)NotificationImportance.Default)
                                      .SetVisibility(NotificationCompat.VisibilityPublic)
                                      .SetStyle(style)
                                      .SetContentIntent(OpenAppIntent())
                                      .SetAutoCancel(true)
                                      .Build();

            manager.Notify(-99, notification);
        }
Пример #19
0
        public static void NotifyAppComeback()
        {
            var context = Application.Context;

            var manager = SetNotificationManager();

            string title   = "5초의 알람으로 돌아와요~";
            string message = "5초의 알람엔 기록, 음성 알람, 의지 알람 등 많은 기능이 있어요."
                             + Environment.NewLine
                             + Environment.NewLine
                             + "앱에서 많은 기능을 확인해보세요~";
            string bigText = "5초의 알람엔 기록, 음성 알람, 의지 알람 등 많은 기능이 있어요."
                             + Environment.NewLine
                             + Environment.NewLine
                             + "앱에서 많은 기능을 확인해보세요~";

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(bigText);

            var notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
            var notification        = notificationBuilder.SetOngoing(false)
                                      .SetSmallIcon(Resource.Drawable.ic_five_seconds_mini)
                                      .SetContentTitle(title)
                                      .SetContentText(message)
                                      .SetPriority((int)NotificationImportance.Default)
                                      .SetVisibility(NotificationCompat.VisibilityPublic)
                                      .SetStyle(style)
                                      .SetContentIntent(OpenAppIntent())
                                      .SetAutoCancel(true)
                                      .Build();

            manager.Notify(-98, notification);
        }
        /// <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)
        {
            var           resultIntent  = GetLauncherActivity();
            PendingIntent pendingIntent = null;

            if (resultIntent != null)
            {
                resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                pendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, 0, resultIntent, 0);
            }

            var notificationSound = Android.Media.RingtoneManager.GetDefaultUri(Android.Media.RingtoneType.Notification);
            var style             = new NotificationCompat.BigTextStyle();

            style.BigText(body);

            var builder = new NotificationCompat.Builder(Android.App.Application.Context, NotificationChannelId)
                          .SetContentTitle(title)
                          .SetAutoCancel(true)
                          .SetContentText(body)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetGroup("push_messages")
                          .SetSmallIcon(Resource.Mipmap.ic_launcher);

            if (pendingIntent != null)
            {
                builder.SetContentIntent(pendingIntent);
            }

            builder.SetSound(notificationSound);

            var notification = builder.Build();

            try
            {
                notification.LedARGB  = Android.Graphics.Color.Argb(1, 29, 113, 184);
                notification.Flags   |= NotificationFlags.ShowLights;
                notification.Flags   |= NotificationFlags.HighPriority;
                notification.LedOnMS  = 1000;
                notification.LedOffMS = 2000;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error: {ex.Message}");
            }

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

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O && !_channelCreated)
            {
                var channel = new NotificationChannel(NotificationChannelId, NotificationChannelName, NotificationImportance.High);
                channel.EnableLights(true);
                channel.EnableVibration(false);
                notificationManager.CreateNotificationChannel(channel);
                _channelCreated = true;
            }
            notificationManager.Notify(id, notification);
        }
Пример #21
0
        public static void NotifyFeedbackAlarm(Alarm alarm, double previousRate, double recentRate)
        {
            var context = Application.Context;

            var manager = SetNotificationManager();

            string title;
            string message;
            string bigText;

            if (alarm != null)
            {
                if (previousRate > recentRate)
                {
                    title   = $"'{alarm.Name}'의 성공률이 좋지 않아요 ㅠ";
                    message = $"최근 '{alarm.Name}'의 성공률이 이전 성공률보다 {(previousRate - recentRate) * 100:0.##}% 낮네요. 조금 더 힘내봅시다!!";
                    bigText = $"최근 '{alarm.Name}'의 성공률이 이전 성공률보다 {(previousRate - recentRate) * 100:0.##}% 낮네요. 조금 더 힘내봅시다!!"
                              + Environment.NewLine
                              + Environment.NewLine
                              + $"앱에서 '{alarm.Name}'의 성공률을 확인해보세요~";
                }
                else
                {
                    title   = $"'{alarm.Name}'의 성공률이 좋네요!";
                    message = $"최근 '{alarm.Name}'의 성공률이 이전 성공률보다 {(recentRate - previousRate) * 100:0.##}% 높아요. 지금 이대로 계속 해봐요!!";
                    bigText = $"최근 '{alarm.Name}'의 성공률이 이전 성공률보다 {(recentRate - previousRate) * 100:0.##}% 높아요. 지금 이대로 계속 해봐요!!"
                              + Environment.NewLine
                              + Environment.NewLine
                              + $"앱에서 '{alarm.Name}'의 성공률을 확인해보세요~";
                }
            }
            else
            {
                title   = $"알람 오류입니다.";
                message = $"개발자 이메일 [email protected]으로 오류 보고해주세요.";
                bigText = $"개발자 이메일 [email protected]으로 오류 보고해주세요.";
            }

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(bigText);

            var notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
            var notification        = notificationBuilder.SetOngoing(false)
                                      .SetSmallIcon(Resource.Drawable.ic_five_seconds_mini)
                                      .SetContentTitle(title)
                                      .SetContentText(message)
                                      .SetPriority((int)NotificationImportance.Default)
                                      .SetVisibility(NotificationCompat.VisibilityPublic)
                                      .SetStyle(style)
                                      .SetContentIntent(OpenAppIntent())
                                      .SetAutoCancel(true)
                                      .Build();

            manager.Notify(alarm.Id, notification);
        }
Пример #22
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");


            var notIntent     = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(context);

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

            // sets notifcation logo
            int resourceId;

            resourceId = Resource.Drawable.xamarin_logo;

            var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId));



            // Generate a notification
            // todo look at notification compat properties
            var builder = new NotificationCompat.Builder(context, channelId)
                          .SetContentIntent(contentIntent)
                          .SetSmallIcon(Resource.Drawable.notification_template_icon_bg)
                          .SetContentTitle(title)
                          .SetContentText(message)
                          .SetStyle(style)
                          .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                          .SetAutoCancel(true)
                          .Extend(wearableExtender);

            var notification = builder.Build();

            manager.Notify(0, notification);

            // this seems to work when the above notify doesnt work

            // var resultIntent = NotificationService.GetLauncherActivity();
            //resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            //var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context);
            //stackBuilder.AddNextIntent(resultIntent);
            //Random random = new Random();
            //int randomNumber = random.Next(9999 - 1000) + 1000;

            //var resultPendingIntent =
            //    stackBuilder.GetPendingIntent(randomNumber, (int)PendingIntentFlags.Immutable);
            //builder.SetContentIntent(resultPendingIntent);
            //// Sending notification
            //var notificationManager = NotificationManagerCompat.From(Application.Context);
            //notificationManager.Notify(randomNumber, builder.Build());
        }
        public void CreateRemoteNotification(string message, string title)
        {
            var context             = Application.Context;
            var builder             = new NotificationCompat.Builder(context);
            var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            var options             = new Bundle();

            // TODO: change getNotificationID or keep ID system
            var id = GetNotificationID();


            // TODO: set drawable icon
            //builder.SetSmallIcon(Resource.Drawable.notificationicon1);
            builder.SetAutoCancel(true);


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

            //textStyle.SetSummaryText (data.SummaryText);
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean)
            {
                // TODO: keep notification style or change
                var style = new NotificationCompat.BigTextStyle();
                style.BigText(message);
                builder.SetStyle(style);
            }

            options.PutString(notificationIntentKey, "1");
            // TODO: Any any Extra Intents
            //options.PutString("", "");

            Intent resultIntent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);

            if (options != null)
            {
                resultIntent.PutExtras(options);
            }

            const int     pendingIntentId     = 0;
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, pendingIntentId, resultIntent, PendingIntentFlags.OneShot);

            builder.SetContentIntent(resultPendingIntent);

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

            if (notificationManager != null)
            {
                notificationManager.Dispose();
            }

            notificationManager = null;
        }
Пример #24
0
        /// <summary>
        /// Notifica Android
        /// </summary>
        /// <param name="title">Titolo</param>
        /// <param name="message">Messaggio</param>
        /// <param name="launchArg">Argomento passato all'applicazione al click della notifica</param>
        public void SendNotification(string title, string message, string launchArg = null)
        {
            const int notificationId = 0;
            Context   context        = (Context ?? Android.App.Application.Context);

            NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
            textStyle.BigText(message);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainActivity.Instance.ChannelID)
                                                 .SetContentTitle(title)
                                                 .SetContentText(message)
                                                 .SetStyle(textStyle);

            if (!string.IsNullOrEmpty(launchArg))
            {
                var bundle = new Android.OS.Bundle();
                bundle.PutString("launch", launchArg);
                if (NotificationIntent != null)
                {
                    NotificationIntent.PutExtra("launch", launchArg);
                    PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, NotificationIntent, PendingIntentFlags.OneShot);
                    builder.SetContentIntent(pendingIntent);
                }
                else
                {
                    builder.SetExtras(bundle);
                }
            }

            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.LollipopMr1)
            {
                builder.SetSmallIcon(Resource.Drawable.ic_notification);
                builder.SetVibrate(new long[] { 100, 200, 300 });
            }
            else
            {
                builder.SetSmallIcon(Resource.Drawable.ic_notification_white);
            }

            // Build the notification:
            Notification notification = builder.Build();

            // Get the notification manager:
            NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            notificationManager.Notify(notificationId, notification);
        }
Пример #25
0
        /// <summary>
        /// The OnCreate
        /// </summary>
        public override void OnCreate()
        {
            context             = this;
            serialPortConnected = false;

            Intent intent = PackageManager
                            .GetLaunchIntentForPackage(PackageName)
                            .SetPackage(null)
                            .SetFlags(ActivityFlags.NewTask | ActivityFlags.ResetTaskIfNeeded);

            PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0);

            exitPendingIntent = PendingIntent.GetBroadcast(this, 0, new Intent("LNG.CMRI.EXIT"), 0);

            bigTextStyle = new NotificationCompat.BigTextStyle();
            bigTextStyle.SetBigContentTitle(prefix);
            bigTextStyle.BigText(defaulttext);

            mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
                       .SetSmallIcon(Resource.Drawable.ic_gas_meter_free_icon_3)
                       .SetContentTitle("L+G CMRI")
                       .SetContentText("CMRI Service Started")
                       .SetStyle(bigTextStyle)
                       //.SetWhen(System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
                       //.SetAutoCancel(false)
                       .SetOnlyAlertOnce(true)
                       .SetProgress(0, 0, false)
                       .SetPriority((int)NotificationPriority.Max)
                       .SetOngoing(true)
                       .SetContentIntent(pendingIntent)
                       //.AddAction(Resource.Drawable.ic_mtrl_chip_close_circle, "EXIT APPLICATION", exitPendingIntent)
                       //.SetFullScreenIntent(pendingIntent,true)
            ;

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

            mNotify = mBuilder.Build();

            StartForeground(Notification_ID, mNotify);

            SERVICE_CONNECTED = true;
            SetFilter();
            usbManager = (UsbManager)GetSystemService(Context.UsbService);

            FindSerialPortDevice();
        }
Пример #26
0
        void ShowNotification(string message)
        {
            try
            {
                Console.WriteLine("SendNotification");
                var notificationManager = NotificationManagerCompat.From(this);

                Console.WriteLine("Created Manager");
                var notificationIntent = new Intent(this, typeof(MainActivity));
                notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

                Console.WriteLine("Created Pending Intent");

                /*var wearableExtender =
                 *  new NotificationCompat.WearableExtender()
                 *      .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background_evolve));*/

                var style = new NotificationCompat.BigTextStyle();
                style.BigText(message);

                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(pendingIntent)
                              .SetContentTitle("Sealegs Notification")
                              .SetAutoCancel(true)
                              .SetStyle(style)
                              .SetSmallIcon(Resource.Drawable.ic_notification)
                              .SetContentText(message);
                //.Extend(wearableExtender);

                // Obtain a reference to the NotificationManager
                var id = Sealegs.Droid.Helpers.Settings.GetUniqueNotificationId();
                Console.WriteLine("Got Unique ID: " + id);

                var notif = builder.Build();
                notif.Defaults = NotificationDefaults.All;
                Console.WriteLine("Notify");
                notificationManager.Notify(id, notif);

                dialogNotify("Sealegs Notification", message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #27
0
        private void btnSendNotificationWithBigText_OnClick(object sender, EventArgs eventArgs)
        {
            // Specify the 'big view' content to display the long
            var bigStyle = new NotificationCompat.BigTextStyle();

            bigStyle.BigText("MUCH MUCH MUCH MUCH MUCH MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE TEXT!!");

            var builder = new NotificationCompat.Builder(Context);

            builder.SetContentTitle("Notification")
            .SetContentText("With Big Text")
            .SetLocalOnly(false)
            .SetSmallIcon(Resource.Drawable.icon7)
            .SetStyle(bigStyle);

            NotificationManagerCompat.From(Context).Notify(116, builder.Build());
        }
        private NotificationCompat.Builder GetBuilder(Alarm alarm, Context context)
        {
            var bigContent = alarm.Id + ":\n" + alarm.Items;
            var content    = alarm.Id + ": " + alarm.Items;

            NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
            textStyle.BigText(bigContent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone))
                                                 .SetSmallIcon(Resource.Drawable.betonotificationtr)
                                                 .SetContentTitle("Hora del medicamento " + alarm.Hour.ToString("hh':'mm"))
                                                 .SetContentText(content)
                                                 .SetStyle(textStyle);

            return(builder);
        }
        private void CreateNotification(String incommingNumber, Context context)
        {
            if (!isNotification)
            {
                return;
            }

            NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            String NOTIFICATION_CHANNEL_ID          = "my_channel_id_01";

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "ATA", NotificationImportance.High);
                notificationChannel.EnableLights(true);
                notificationChannel.SetVibrationPattern(new long[] { 0, 1000, 500, 1000 });
                notificationChannel.EnableVibration(true);
                notificationManager.CreateNotificationChannel(notificationChannel);
            }

            var uiIntent = new Intent(context, typeof(MainActivity));

            uiIntent.PutExtra("FromNotification", true);
            var resultPendingIntent = PendingIntent.GetActivity(context, 0, uiIntent, PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder      notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
            NotificationCompat.BigTextStyle textStyle           = new NotificationCompat.BigTextStyle();
            notificationBuilder.SetAutoCancel(true)
            .SetDefaults(Notification.ColorDefault)
            .SetSmallIcon(Resource.Drawable.myReportIcon)
            .SetPriority((int)NotificationPriority.High)
            .SetContentIntent(resultPendingIntent)
            .SetContentTitle("ATA-Blocking Notification")
            .SetGroupSummary(true)
            .SetVibrate(new long[0])
            .SetGroup("ATA_GROUP")
            //.SetOngoing(true)
            .SetContentText("Anti-Telemarketer blocked a phone call from " + incommingNumber);

            //Add intent filters for each action and register them on a broadcast receiver
            notificationBuilder.SetStyle(textStyle);
            notificationManager.Notify(mark, notificationBuilder.Build());
            mark++;
        }
Пример #30
0
        public override void OnReceive(Context context, Intent intent)
        {
            var bigStyle = new NotificationCompat.BigTextStyle().BigText("Telah Terjadi Tsunami");
            // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
            NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
                                                 //  .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("Sirine Tsunami")
                                                 .SetContentText("Sirine Tsunami")
                                                 .SetAutoCancel(true)
                                                 .SetStyle(bigStyle)
                                                 .SetSound(soundUri)
                                                 .SetPriority(NotificationCompat.PriorityMax)
                                                 .SetSmallIcon(Resource.Drawable.icontsunami);

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetVisibility(NotificationCompat.VisibilityPublic);
            }

            Intent        intents       = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://inatews.bmkg.go.id/terkini.php"));
            PendingIntent pendingIntent = PendingIntent.GetActivity(context, MainActivity.NOTIFICATION_ID, intents, PendingIntentFlags.UpdateCurrent);

            Intent buttonIntent = new Intent(context, typeof(DissmisService));

            buttonIntent.PutExtra("notificationId", MainActivity.CHANNEL_ID);
            PendingIntent dismissIntent = PendingIntent.GetBroadcast(context, MainActivity.NOTIFICATION_ID, buttonIntent, PendingIntentFlags.CancelCurrent);

            builder.AddAction(Resource.Drawable.abc_ic_menu_overflow_material, "VIEW", pendingIntent);
            builder.AddAction(Resource.Drawable.abc_ic_menu_cut_mtrl_alpha, "DISMISS", dismissIntent);

            NotifyBroadcastReceived.ringtone = NotifyBroadcastReceived.ringtone ?? RingtoneManager.GetRingtone(context, soundUri);

            if (!NotifyBroadcastReceived.ringtone.IsPlaying)
            {
                NotifyBroadcastReceived.ringtone.Play();
            }

            notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build());
        }
Пример #31
0
        public override void OnReceive(Context context, Intent intent)
        {
            Toast.MakeText(context, "Alarm showing now", ToastLength.Long).Show();
            var med                                 = intent.GetStringExtra("MedicineName");
            int number                              = Convert.ToInt32(intent.GetStringExtra("NumberofTimes"));
            var title                               = intent.GetStringExtra("title");
            var notIntent                           = new Intent(context, typeof(MainActivity));
            var contentIntent                       = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var style                               = new NotificationCompat.BigTextStyle();
            var check                               = intent.GetStringExtra("CheckValue");
            NotificationManager manager             = (NotificationManager)context.GetSystemService(Context.NotificationService);
            PendingIntent       resultPendingIntent = PendingIntent.GetActivity(context, 0, intent, Android.App.PendingIntentFlags.UpdateCurrent);

            Android.Net.Uri            alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            NotificationCompat.Builder builder    = new NotificationCompat.Builder(context)
                                                    .SetSmallIcon(Resource.Drawable.Icon)
                                                    .SetContentTitle("MedTrack Notification")
                                                    .SetContentText(String.Format("It's time to take {0}- {1} times today", med, number))
                                                    .SetSound(alarmSound)
                                                    .SetStyle(style)
                                                    .SetAutoCancel(true)
                                                    .SetContentIntent(resultPendingIntent);

            Notification notification = builder.Build();

            manager.Notify(0, notification);

            if (number == 2 || (intent.GetStringExtra("evening") == "true"))
            {
                var intentNew = new Intent(context, typeof(RepeatEveningAlarmActivity));
                intentNew.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(intentNew);
            }
            else if ((number == 3) || ((number > 3 && (intent.GetStringExtra("check") == "true"))) ||
                     (number > 3 && (intent.GetStringExtra("afternoon") == "true")))
            {
                var intentNew = new Intent(context, typeof(RepeatAfternoonAlarmActivity));
                intentNew.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(intentNew);
            }
        }
Пример #32
0
        public override void OnReceive(Context context, Intent intent)
        {
            Toast.MakeText(context, "Alarm showing now", ToastLength.Long).Show();
            var med = intent.GetStringExtra("MedicineName");
            int number = Convert.ToInt32(intent.GetStringExtra("NumberofTimes"));
            var title = intent.GetStringExtra("title");
            var notIntent = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            var style = new NotificationCompat.BigTextStyle();
            var check = intent.GetStringExtra("CheckValue");
            NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, intent, Android.App.PendingIntentFlags.UpdateCurrent);

            Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                            .SetSmallIcon(Resource.Drawable.Icon)
                            .SetContentTitle("MedTrack Notification")
                            .SetContentText(String.Format("It's time to take {0}- {1} times today", med, number))
                            .SetSound(alarmSound)
                            .SetStyle(style)
                            .SetAutoCancel(true)
                            .SetContentIntent(resultPendingIntent);

            Notification notification = builder.Build();
            manager.Notify(0, notification);
            
            if(number == 2 || (intent.GetStringExtra("evening") == "true"))
            {
                var intentNew = new Intent(context, typeof(RepeatEveningAlarmActivity));
                intentNew.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(intentNew);
            }
            else if((number ==3) || ((number >3 && (intent.GetStringExtra("check") == "true")))
                ||  (number >3 && (intent.GetStringExtra("afternoon") == "true")))
            {            
                var intentNew = new Intent(context, typeof(RepeatAfternoonAlarmActivity));
                intentNew.AddFlags(ActivityFlags.NewTask);             
                context.StartActivity(intentNew);
            }
        }
Пример #33
0
		public override void OnReceive (Context context, Intent intent)
		{

			var message = intent.GetStringExtra ("message");
			var title = intent.GetStringExtra ("title");

			var notIntent = new Intent (context, typeof(MainActivity));
			var contentIntent = PendingIntent.GetActivity (context, 0, notIntent, PendingIntentFlags.CancelCurrent);
			var manager = NotificationManagerCompat.From (context);
			
						var style = new NotificationCompat.BigTextStyle();
						style.BigText(message);
			
						int resourceId;
						if (App.SelectedModel.VehicleType == "Car")
							resourceId = Resource.Drawable.Car;
						else if (App.SelectedModel.VehicleType == "Bike")
							resourceId = Resource.Drawable.Bike;
						else
							resourceId = Resource.Drawable.Other;
			
						var wearableExtender = new NotificationCompat.WearableExtender()
				.SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId))
							;
			
						//Generate a notification with just short text and small icon
			var builder = new NotificationCompat.Builder (context)
							.SetContentIntent (contentIntent)
							.SetSmallIcon (Resource.Drawable.ic_launcher)
							.SetContentTitle(title)
							.SetContentText(message)
							.SetStyle(style)
							.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
							.SetAutoCancel(true)
							.Extend(wearableExtender);
			
			
						var notification = builder.Build();
						manager.Notify(0, notification);
		}
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var button = FindViewById <Button> (Resource.Id.myButton);

            button.Click += delegate {
                var pendingIntent = PendingIntent.GetActivity(this, 100,
                                                              new Intent(this, typeof(MainActivity)),
                                                              PendingIntentFlags.UpdateCurrent);
                var largeIcon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.monkey);

                var builder = new NotificationCompat.Builder(this)
                              .SetSmallIcon(Resource.Drawable.ic_logo)
                              .SetLargeIcon(largeIcon)
                              .SetContentText("Short Service announcement")
                              .SetContentTitle("Page 1")
                              .SetContentIntent(pendingIntent);

                var secondPageStyle = new NotificationCompat.BigTextStyle();
                secondPageStyle.BigText("Xamarin.Android goes on your Android Wear too");

                var secondNotification = new NotificationCompat.Builder(this)
                                         .SetSmallIcon(Resource.Drawable.ic_logo)
                                         .SetLargeIcon(largeIcon)
                                         .SetContentTitle("Page 2")
                                         .SetStyle(secondPageStyle)
                                         .Build();

                var twoPageNotification = new NotificationCompat.WearableExtender()
                                          .AddPage(secondNotification)
                                          .Extend(builder)
                                          .Build();

                NotificationManagerCompat.From(this).Notify("multi-page-notification", 1000, twoPageNotification);
            };
        }
Пример #35
0
        void SendNotification(string message)
        {
            try
            {
                Console.WriteLine("SendNotification");
                var notificationManager = NotificationManagerCompat.From(this);

                Console.WriteLine("Created Manager");
                var notificationIntent = new Intent(this, typeof(MainActivity));
                notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

                Console.WriteLine("Created Pending Intent");

                var style = new NotificationCompat.BigTextStyle();
                style.BigText(message);

                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(pendingIntent)
                              .SetContentTitle("Developer Open Space")
                              .SetAutoCancel(true)
                              .SetStyle(style)
                              .SetSmallIcon(Resource.Drawable.ic_notification)
                              .SetContentText(message);

                // Obtain a reference to the NotificationManager
                var id = open.conference.app.Droid.Helpers.Settings.GetUniqueNotificationId();
                Console.WriteLine("Got Unique ID: " + id);
                var notif = builder.Build();
                notif.Defaults = NotificationDefaults.All;
                Console.WriteLine("Notify");
                notificationManager.Notify(id, notif);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #36
0
        void CreateNotification(string title, string message, int notifyId, string tag, Bundle extras)
        {
            System.Diagnostics.Debug.WriteLine(string.Format("{0} - PushNotification - Message {1} : {2}", PushNotificationKey.DomainName,title,message));

            NotificationCompat.Builder builder = null;
            Context context = Android.App.Application.Context;

            if (CrossPushNotification.SoundUri == null)
            {
                CrossPushNotification.SoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            }
            try
            {

                if (CrossPushNotification.IconResource == 0)
                {
                    CrossPushNotification.IconResource = context.ApplicationInfo.Icon;
                }
                else
                {
                    string name = context.Resources.GetResourceName(CrossPushNotification.IconResource);

                    if (name == null)
                    {
                        CrossPushNotification.IconResource = context.ApplicationInfo.Icon;

                    }
                }

            }
            catch (Android.Content.Res.Resources.NotFoundException ex)
            {
                CrossPushNotification.IconResource = context.ApplicationInfo.Icon;
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            Intent resultIntent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);

            //Intent resultIntent = new Intent(context, typeof(T));

             if (extras != null) { resultIntent.PutExtras(extras); }

            // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
            const int pendingIntentId = 0;
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, pendingIntentId, resultIntent, PendingIntentFlags.OneShot);

            // Build the notification
            builder = new NotificationCompat.Builder(context)
                      .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(title) // Set the title
                      .SetSound(CrossPushNotification.SoundUri)
                      .SetSmallIcon(CrossPushNotification.IconResource) // This is the icon to display
                      .SetContentText(message); // the message to display.

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) {
                // Using BigText notification style to support long message
                var style = new NotificationCompat.BigTextStyle ();
                style.BigText (message);
                builder.SetStyle (style);
            }

            NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            notificationManager.Notify(tag, notifyId, builder.Build());
        }
Пример #37
0
        void SendNotification(string message)
        {
            try
            {
                Console.WriteLine ("SendNotification");
                var notificationManager = NotificationManagerCompat.From (this);

                Console.WriteLine ("Created Manager");
                var notificationIntent = new Intent(this, typeof(MainActivity));
                notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

                Console.WriteLine ("Created Pending Intent");
                /*var wearableExtender =
                    new NotificationCompat.WearableExtender()
                        .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background_evolve));*/

                var style = new NotificationCompat.BigTextStyle();
                style.BigText(message);

                var builder = new NotificationCompat.Builder(this)
                    .SetContentIntent(pendingIntent)
                    .SetContentTitle("Xamarin Evolve")
                    .SetAutoCancel(true)
                    .SetStyle(style)
                    .SetSmallIcon(Resource.Drawable.ic_notification)
                    .SetContentText(message);
                //.Extend(wearableExtender);

                // Obtain a reference to the NotificationManager
                var id = XamarinEvolve.Droid.Helpers.Settings.GetUniqueNotificationId();
                Console.WriteLine ("Got Unique ID: " + id);
                var notif = builder.Build ();
                notif.Defaults = NotificationDefaults.All;
                Console.WriteLine ("Notify");
                notificationManager.Notify(id, notif);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #38
0
		private async Task<int> Notify(AsyncNetwork network, string title, string message) {
			Setting setting = db.Table<Setting> ().FirstOrDefault ();

			if (!setting.Notifications)
				return 0;

			// Set up an intent so that tapping the notifications returns to this app:
			Intent intent = new Intent (this, typeof(MainActivity));

			// Create a PendingIntent; we're only using one PendingIntent (ID = 0):
			const int pendingIntentId = 0;
			PendingIntent pendingIntent = 
				PendingIntent.GetActivity (this, pendingIntentId, intent, PendingIntentFlags.OneShot);
			var msg = message;
			if (msg.StartsWith ("#image")) {
				msg = "You received an image.";
			}
			NotificationCompat.Builder builder = new NotificationCompat.Builder (this)
				.SetContentIntent (pendingIntent)
				.SetContentTitle (title)
				.SetContentText (msg)
				.SetAutoCancel (true)
				.SetSmallIcon (Resource.Drawable.Icon);

			if (setting.Sound) {
				builder.SetSound (RingtoneManager.GetDefaultUri (RingtoneType.Notification));
			}
				

			if ((int)Android.OS.Build.VERSION.SdkInt >= 14) {
				if (setting.Led) {
					builder.SetLights (Android.Graphics.Color.Magenta, 500, 500);
				}
				if (message.StartsWith ("#image")) {
					// Instantiate the Image (Big Picture) style:
					NotificationCompat.BigPictureStyle picStyle = new NotificationCompat.BigPictureStyle ();

					// Convert the image to a bitmap before passing it into the style:
					picStyle.BigPicture (await network.GetImageBitmapFromUrlNoCache (message.Substring ("#image ".Length)));

					// Set the summary text that will appear with the image:
					picStyle.SetSummaryText (msg);

					// Plug this style into the builder:
					builder.SetStyle (picStyle);
				} else {
					NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle ();

					// Fill it with text:
					textStyle.BigText (message);

					// Set the summary text:
					textStyle.SetSummaryText ("New message");
					builder.SetStyle (textStyle);
				}
			}

			// Build the notification:
			Notification notification = builder.Build();

			// Get the notification manager:
			NotificationManager notificationManager =
				GetSystemService (Context.NotificationService) as NotificationManager;

			// Publish the notification:
			const int notificationId = 0;
			notificationManager.Notify (notificationId, notification);

			if (setting.Vibrate) {
				Vibrator v = (Vibrator)GetSystemService (Context.VibratorService); // Make phone vibrate
				v.Vibrate (300);
			}

			return notificationId;
		}