Пример #1
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);
		}
Пример #2
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);
        }
		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);
		}
Пример #4
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);
        }
Пример #5
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());
        }
        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);
        }
Пример #7
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);
        }
Пример #8
0
        /// <summary>
        /// The UpdateNotification
        /// </summary>
        /// <param name="title">The title<see cref="string"/></param>
        /// <param name="message">The message<see cref="string"/></param>
        /// <param name="bShowProgressBar">The bShowProgressBar<see cref="bool"/></param>
        public void UpdateNotification(string title, string message, bool bShowProgressBar)
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                if (title != null)
                {
                    bigTextStyle.SetBigContentTitle(prefix + " : " + title);
                }

                if (message != null)
                {
                    bigTextStyle.BigText(string.IsNullOrWhiteSpace(message) ? defaulttext : message);
                }

                mBuilder.SetProgress(0, 0, bShowProgressBar)
                .SetStyle(bigTextStyle)
                ;
            }
            else
            {
                if (title != null)
                {
                    mBuilder.SetContentTitle(prefix + " : " + title);
                }

                if (message != null)
                {
                    mBuilder.SetContentText(string.IsNullOrWhiteSpace(message) ? defaulttext : message);
                }
            }
            notificationManager.Notify(Notification_ID, mBuilder.Build());
        }
Пример #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);
        }
        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);
        }
Пример #11
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();
        }
Пример #12
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);
        }
Пример #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(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);
        }
Пример #14
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);
        }
Пример #15
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");
        }
Пример #16
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);
        }
        /// <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);
        }
Пример #18
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);
        }
Пример #19
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;
        }
Пример #21
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);
        }
Пример #22
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();
        }
Пример #23
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);
        }
Пример #25
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);
            }
        }
Пример #26
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);
            };
        }
Пример #28
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);
            }
        }
Пример #29
0
        public void IF_PushLocalNotification(string title, string content, string icon)
        {
            Random rnd   = new Random();
            int    month = rnd.Next(1, 99999);


            var builder = new NotificationCompat.Builder(SupportWidgetXFSetup.Activity)
                          .SetContentTitle(title)
                          .SetContentText(content)
                          .SetPriority(2)
                          .SetDefaults(0)
                          .SetAutoCancel(true)
                          .SetVibrate(new long[1000]);

            try
            {
                if (icon != null)
                {
                    var image = SupportWidgetXFSetup.Activity.Resources.GetIdentifier(icon, "drawable", SupportWidgetXFSetup.Activity.PackageName);
                    builder.SetSmallIcon(image);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }

            var textStyle = new NotificationCompat.BigTextStyle();

            textStyle.BigText(content);
            builder.SetStyle(textStyle);

            var notigi = builder.Build();
            var notificationManager = SupportWidgetXFSetup.Activity.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(month, notigi);
        }
        void SendNotification(Context context, string title, string message)
        {
            Random rm             = new Random();
            int    NotificationId = rm.Next(9999);
            var    channelId      = "MyApp Channel";
            var    mainIntent     = new Intent(context, typeof(MainActivity));

            mainIntent.PutExtra("NotificationId", NotificationId);

            mainIntent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(context, NotificationId, mainIntent, PendingIntentFlags.UpdateCurrent);


            var style = new NotificationCompat.BigTextStyle();

            style.BigText(title);

            var defaultSoundUri     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            var notificationBuilder = new NotificationCompat.Builder(context, channelId)
                                      .SetContentTitle("MyApp - " + title)
                                      .SetContentText(message)
                                      .SetAutoCancel(true)
                                      .SetSound(defaultSoundUri)
                                      .SetContentIntent(pendingIntent)
                                      .SetSmallIcon(Resource.Drawable.icon);

            var notificationManager = NotificationManager.FromContext(context);

            if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O)
            {
                NotificationChannel mChannel = new NotificationChannel(channelId, "MyApp", NotificationImportance.High);
                notificationManager.CreateNotificationChannel(mChannel);
                notificationBuilder.SetChannelId(channelId);
            }

            notificationManager.Notify(NotificationId, notificationBuilder.Build());
        }
        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);
        }
Пример #32
0
        private static Notification CreateForNotifyRoutineStart(Routine routine)
        {
            var context = Application.Context;

            var wise_sayings = context.Resources.GetStringArray(Resource.Array.wise_sayings);
            var random       = new Random();

            string title   = $"{routine.Name} 시작!";
            string message = wise_sayings[random.Next(wise_sayings.Length)];

            var style = new NotificationCompat.BigTextStyle();

            style.BigText(message);

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

            var actionIntent2 = CreateActionIntent("루틴 시작", routine.Id);
            var pIntent2      = PendingIntent.GetBroadcast(context, routine.Id, actionIntent2, PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
            var notification        = notificationBuilder.SetOngoing(false)
                                      .SetSmallIcon(Resource.Drawable.ic_miracle_routine_mini)
                                      .SetContentTitle(title)
                                      .SetContentText(message)
                                      .SetPriority((int)NotificationImportance.High)
                                      .SetVisibility(NotificationCompat.VisibilityPublic)
                                      .SetSound(alarmSound)
                                      .SetVibrate(vibrationPattern)
                                      .SetAutoCancel(true)
                                      .SetStyle(style)
                                      .SetContentIntent(pIntent2)
                                      .AddAction(0, "루틴 시작", pIntent2)
                                      .Build();

            return(notification);
        }
Пример #33
0
        private void btnSendNotificationWithMultiplePages_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.icon10)
            .SetStyle(bigStyle);

            // Create a big text style for the second page
            var secondPageStyle = new NotificationCompat.BigTextStyle();

            secondPageStyle.SetBigContentTitle("Page 2")
            .BigText("A lot of text...");


            // Create second page notification
            Notification secondPageNotification = new NotificationCompat.Builder(Context)
                                                  .SetStyle(secondPageStyle)
                                                  .Build();

            // Extend the notification builder with the second page
            var notification = builder
                               .Extend(new NotificationCompat.WearableExtender()
                                       .AddPage(secondPageNotification))
                               .Build();


            NotificationManagerCompat.From(Context).Notify(119, notification);
        }
Пример #34
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);
            }
        }
Пример #35
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;
		}
Пример #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());
        }