public void DisplayNotificationIfNextGameIsToday(IList<Fixture> fixtures)
        {
            //var now = new DateTime(2014, 9, 14, 15, 00, 00);
            var now = DateTime.Now;
            var fixture = fixtures[0];
            var notificationManager = (NotificationManager)_context.GetSystemService(Context.NOTIFICATION_SERVICE);

            if (fixture.Date.Date == now.Date && now <= fixture.Date)
            {
                var bigText = new Notification.BigTextStyle();
                bigText.BigText(fixture.HomeTeam + " v " + fixture.AwayTeam);

                var footballTodayMessage = "Football today at " + fixture.Date.ToString("HH:mm");

                bigText.SetBigContentTitle(footballTodayMessage);

                var notification = new Notification.Builder(_context)
                    .SetSmallIcon(R.Drawables.Icon)
                    .SetStyle(bigText)
                    .SetTicker(footballTodayMessage)
                    .Build();

                notificationManager.Notify(1, notification);
            }
            else
            {
                notificationManager.CancelAll();
            }
        }
        private void ExibirInboxNotificacao()
        {
            Notification.Builder builder = new Notification.Builder(this)
                .SetContentTitle ("Sample Notification")
                .SetContentText ("Hello World! This is my first action notification!")
                .SetDefaults (NotificationDefaults.Sound)
                .SetSmallIcon (Resource.Drawable.Icon);

            // Instantiate the Inbox style:
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();

            // Set the title and text of the notification:
            builder.SetContentTitle ("5 new messages");
            builder.SetContentText ("*****@*****.**");

            // Generate a message summary for the body of the notification:
            inboxStyle.AddLine ("Cheeta: Bananas on sale");
            inboxStyle.AddLine ("George: Curious about your blog post");
            inboxStyle.AddLine ("Nikko: Need a ride to Evolve?");
            inboxStyle.SetSummaryText ("+2 more");

            // Plug this style into the builder:
            builder.SetStyle (inboxStyle);

            Notification notification = builder.Build();

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

            const int notificationId = 0;
            notificationManager.Notify (notificationId, notification);
        }
		private void CreateNotifications(Context context, string action, bool isMessageNeeded = true, bool isToastNeeded = true)
		{
			#if DEBUG
			try {
				if (isMessageNeeded)
				{
					Notification notification = new Notification.Builder(context)
						.SetContentTitle ("BluetoothNotify intent received " + action)
						.SetContentText ("message sent at" + System.DateTime.Now.ToLongTimeString ())
						.SetSmallIcon (Resource.Drawable.icon)
						.Build ();

					NotificationManager nMgr = (NotificationManager)context.GetSystemService (Android.Content.ContextWrapper.NotificationService);
					nMgr.Notify (0, notification);
				}

				if (isToastNeeded)
				{
					var myHandler = new Handler ();
					myHandler.Post (() =>  {
						Toast.MakeText (context, "BluetoothNotify intent received " + action, ToastLength.Long).Show ();
					});
				}
				
			} catch (Exception ex) {
				Log.Info ("com.tarabel.bluetoothnotify", "CreateNotification error in IntentReceiver " + ex.ToString());
			}
			#endif
		}
		private void SendNotification (Bundle data) {
			Intent intent;
			string type = data.GetString("type");

			intent = new Intent (this, typeof(MainActivity));
			if(type.Equals(PUSH_INVITE)) {
				ViewController.getInstance().pushEventId = Convert.ToInt32(data.GetString("eventId"));
				intent.SetAction(PUSH_INVITE);
			} else if(type.Equals(PUSH_EVENT_UPDATE)) {
				ViewController.getInstance().pushEventId = Convert.ToInt32(data.GetString("eventId"));
				intent.SetAction(PUSH_EVENT_UPDATE);
			} else if(type.Equals(PUSH_DELETE)) {
				//nothing else need to be done
				//MainActivity will refresh the events on start
			}

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

			var notificationBuilder = new Notification.Builder(this)
				.SetSmallIcon (Resource.Drawable.pushnotification_icon)
				.SetContentTitle (data.GetString("title"))
				.SetContentText (data.GetString ("message"))
				.SetVibrate(new long[] {600, 600})
				.SetAutoCancel (true)
				.SetContentIntent (pendingIntent);

			var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
			notificationManager.Notify (notificationId, notificationBuilder.Build());
			notificationId++;
		}
        // Creates a new notification depending on makeHeadsUpNotification.
        public Notification CreateNotification(Context context, Intent intent)
        {
            // indicate that this sms comes from server
            intent.PutExtra ("source", "server");

            // Parse bundle extras
            string contactId = intent.GetStringExtra("normalizedPhone");
            string message = intent.GetStringExtra("message");

            // Getting contact infos
            var contact = Contact.GetContactByPhone (contactId, context);

            var builder = new Notification.Builder (context)
                .SetSmallIcon (Resource.Drawable.icon)
                .SetPriority ((int)NotificationPriority.Default)
                .SetCategory (Notification.CategoryMessage)
                .SetContentTitle (contact.DisplayName != "" ? contact.DisplayName : contactId)
                .SetContentText (message)
                .SetSound (RingtoneManager.GetDefaultUri (RingtoneType.Notification));

            var fullScreenPendingIntent = PendingIntent.GetActivity (context, 0,
                intent, PendingIntentFlags.CancelCurrent);
                builder.SetContentText (message)
                       .SetFullScreenIntent (fullScreenPendingIntent, true)
                       .SetContentIntent (fullScreenPendingIntent);

            return builder.Build ();
        }
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			var toggle_alarm_operation = new Intent (this, typeof(FindPhoneService));

			toggle_alarm_operation.SetAction(FindPhoneService.ACTION_TOGGLE_ALARM);
			var toggle_alarm_intent = PendingIntent.GetService (this, 0, toggle_alarm_operation, PendingIntentFlags.CancelCurrent);
			Android.App.Notification.Action alarm_action = new Android.App.Notification.Action (Resource.Drawable.alarm_action_icon, "", toggle_alarm_intent);
			var cancel_alarm_operation = new Intent (this, typeof(FindPhoneService));
			cancel_alarm_operation.SetAction (FindPhoneService.ACTION_CANCEL_ALARM);
			var cancel_alarm_intent = PendingIntent.GetService (this, 0, cancel_alarm_operation, PendingIntentFlags.CancelCurrent);
			var title = new SpannableString ("Find My Phone");
			title.SetSpan (new RelativeSizeSpan (0.85f), 0, title.Length(), SpanTypes.PointMark);
			notification = new Notification.Builder (this)
				.SetContentTitle (title)
				.SetContentText ("Tap to sound an alarm on phone")
				.SetSmallIcon (Resource.Drawable.ic_launcher)
				.SetVibrate (new long[]{ 0, 50 })
				.SetDeleteIntent (cancel_alarm_intent)
				.Extend (new Notification.WearableExtender ()
					.AddAction (alarm_action)
					.SetContentAction (0)
					.SetHintHideIcon (true))
				.SetLocalOnly (true)
				.SetPriority ((int)NotificationPriority.Max);
			((NotificationManager)GetSystemService (NotificationService))
				.Notify (FIND_PHONE_NOTIFICATION_ID, notification.Build ());

			Finish ();
		}
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
	        if (builder == null)
	        {
		        builder = new Notification.Builder(context);
	        }

		    builder.SetContentTitle(this.Title);
			if (this.TotalBytes > 0 && this.CurrentBytes != -1)
            {
                builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
            }
            else
            {
                builder.SetProgress(0, 0, true);
            }
            builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
            builder.SetContentInfo(context.GetString(Resource.String.time_remaining_notification, Helpers.GetTimeRemaining(this.TimeRemaining)));
            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return builder.Notification;
        }
Example #8
0
        protected void ShowNotification()
        {
            /*
            Notification.Builder builder = new Notification.Builder(this)
                .SetContentTitle("Break Time!")
                .SetContentText("You have passed a 3.5 hours and should take your 10 minute break if possible")
                .SetSmallIcon(Resource.Drawable.coffee);

            Notification notification = builder.Build();
            NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            const int notificationId = 0;
            notificationManager.Notify(notificationId, notification);
             *
             * */
            Notification notification;

            RemoteViews bigView = new RemoteViews(ApplicationContext.PackageName, Resource.Layout.notification_large);

            //PendingIntent testIntent = PendingIntent.GetActivities

            Notification.Builder builder = new Notification.Builder(this);
            notification = builder.SetContentTitle("Accrued Break Time")
                .SetContentText("You have reached a certain threshold to take a required break. Slide down for more details")
                .SetSmallIcon(Resource.Drawable.bussmall)
                .SetLargeIcon(Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.bus))
                .Build();

            notification.BigContentView = bigView;

            NotificationManager manager = (NotificationManager)GetSystemService(Context.NotificationService) as NotificationManager;
            manager.Notify(0, notification);
        }
		private void ShowLocalNotification (Context context, Intent intent)
		{
			var launch = new Intent (context, typeof (MainActivity));

			const int pendingIntentId = 0;
			var pendingIntent = 
				PendingIntent.GetActivity (context, 
					pendingIntentId, launch, PendingIntentFlags.UpdateCurrent);
					
			var msg = intent.Extras.GetString ("message");

			if (!String.IsNullOrEmpty (msg))
			{
				// Instantiate the builder and set notification elements:
				Notification.Builder builder = new Notification.Builder (this)
					.SetContentIntent (pendingIntent)
					.SetContentTitle ("New Notification!")
					.SetContentText (msg)
					.SetDefaults (NotificationDefaults.Sound);

				// 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);
			}
		}
Example #10
0
        protected override void OnCreate(Bundle bundle)
        {
            var intentFilter = new IntentFilter();
            intentFilter.AddAction(ConnectivityManager.ConnectivityAction);
            RegisterReceiver(new Connectivity(), intentFilter);

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            connectivity.Singleton.MessageEvents.Change += (object s, UIChangedEventArgs ea) =>
            {
                if (ea.ModuleName == "Notification")
                {
                    RunOnUiThread(() =>
                        {
                            var builder = new Notification.Builder(this)
                                    .SetAutoCancel(true)
                                    .SetContentTitle("Network state changed")
                                    .SetContentText(ea.Info)
                                    .SetDefaults(NotificationDefaults.Vibrate)
                                    .SetContentText(ea.Info);

                            var notificationManager = (NotificationManager)GetSystemService(NotificationService);
                            notificationManager.Notify(ButtonClickNotificationId, builder.Build());
                        });
                }
            };

            LoadApplication(new App());
        }
        protected override void OnMessage(Context context, Intent intent)
        {

            string message = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "Doctor Notification";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI. 
                PendingIntent contentIntent =
                    PendingIntent.GetActivity(context, 0,
                    new Intent(this, typeof(MainActivity)), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);

                ShowPopUp(context, message);
            }
        }
Example #12
0
 public override void OnReceive(Context context, Intent intent)
 {
     var str1 = intent.GetStringExtra ("team1");
     var str2 = intent.GetStringExtra ("team2");
     var count1 = intent.GetStringExtra ("count");
     var iconId = intent.GetStringExtra ("icon");
     Console.WriteLine ("Servise Start");
     PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
     PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Partial, "NotificationReceiver");
     w1.Acquire ();
     Notification.Builder builder = new Notification.Builder (context)
         .SetContentTitle (context.Resources.GetString(Resource.String.matchIsStarting))
         .SetContentText (str1+" VS. "+str2)
         .SetSmallIcon (Convert.ToInt32(iconId));
     // Build the notification:
     Notification notification = builder.Build();
     notification.Defaults = NotificationDefaults.All;
     // Get the notification manager:
     NotificationManager notificationManager = (NotificationManager)context.GetSystemService (Context.NotificationService);
     // Publish the notification:
     int notificationId = Convert.ToInt32(count1);
     notificationManager.Notify (notificationId, notification);
     w1.Release ();
     var tempd = DateTime.UtcNow;
     Console.WriteLine ("Alarm: " + tempd);
 }
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);
            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return builder.Notification;
        }
 public override void OnReceive(Context context, Intent intent)
 {
     var connectivityManager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);
     var info = connectivityManager.ActiveNetworkInfo;
     if (info != null && info.IsConnected)
     {
         //do stuff
         var wifiManager = (WifiManager)context.GetSystemService(Context.WifiService);
         var wifiInfo = wifiManager.ConnectionInfo;
         var ssid = wifiInfo.SSID;
         if (ssid == "\"jackstack\"")
         {
             var nMgr = (NotificationManager)context.GetSystemService(Context.NotificationService);
             //var notification = new Notification(Resource.Drawable.icon, $"Connected to {ssid}!");
             var pendingIntent = PendingIntent.GetActivity(context, 0, new Intent(context, typeof(MainActivity)), 0);
             //notification.SetLatestEventInfo(context, "Wifi Connected", "Wifi Connected Detail", pendingIntent);
             var notification = new Notification.Builder(context)
                 .SetSmallIcon(Resource.Drawable.icon)
                 .SetTicker($"Connected to {ssid}!")
                 .SetContentTitle("Wifi Connected")
                 .SetContentText("Wifi Connected Detail")
                 .SetContentIntent(pendingIntent)
                 .Build();
             nMgr.Notify(0, notification);
         }
     }
 }
Example #15
0
        public override void OnReceive(Context context, Intent intent)
        {
            string message = intent.GetStringExtra("message");
            string title = intent.GetStringExtra("title");

            Intent notIntent = new Intent(context, typeof(NotificationService));

            PendingIntent contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            NotificationManager manager = NotificationManager.FromContext(context);

            var bigTextStyle = new Notification.BigTextStyle()
                        .SetBigContentTitle(title)
                        .BigText(message);

            Notification.Builder builder = new Notification.Builder(context)
                .SetContentIntent(contentIntent)
                .SetSmallIcon(Resource.Drawable.icon)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetStyle(bigTextStyle)
                .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                .SetAutoCancel(true)
                .SetPriority((int)NotificationPriority.High)
                .SetVisibility(NotificationVisibility.Public)
                .SetDefaults(NotificationDefaults.Vibrate)
                .SetCategory(Notification.CategoryAlarm);

            if (!MainActivity.IsActive)
            {
                manager.Notify(0, builder.Build());
                StartWakefulService(context, notIntent);
            }
        }
      public Notification Build(Builder b) {
        Notification.Builder builder = new Notification.Builder(b.Context);
        builder.SetContentTitle(b.ContentTitle)
          .SetContentText(b.ContentText)
          .SetTicker(b.Notification.TickerText)
          .SetSmallIcon(b.Notification.Icon, b.Notification.IconLevel)
          .SetContentIntent(b.ContentIntent)
          .SetDeleteIntent(b.Notification.DeleteIntent)
          .SetAutoCancel((b.Notification.Flags & NotificationFlags.AutoCancel) != 0)
          .SetLargeIcon(b.LargeIcon)
          .SetDefaults(b.Notification.Defaults);

        if (b.Style != null) {
          if (b.Style is BigTextStyle) {
            BigTextStyle staticStyle = b.Style as BigTextStyle;
            Notification.BigTextStyle style = new Notification.BigTextStyle(builder);
            style.SetBigContentTitle(staticStyle.BigContentTitle)
              .BigText(staticStyle.bigText);
            if (staticStyle.SummaryTextSet) {
              style.SetSummaryText(staticStyle.SummaryText);
            }
          }
        }

        return builder.Build();
      }
		public void ShowNotification(string title, string messageTitle, string messege, bool handleClickNeeded )
		{
			try
			{
				// Set up an intent so that tapping the notifications returns to this app:
				Intent intent = new Intent ( Application.Context , typeof(  NotificationClick ));
				//intent.RemoveExtra ("MyData");
				intent.PutExtra ("Message", messege);
				intent.PutExtra ("Title", title);

				string chatMsg = messege;
				string chatTouserID = "";

				if( title == "chat" )
				{
					string[] delimiters = { "&&" };
					string[] clasIDArray = messege.Split(delimiters, StringSplitOptions.None);
					chatMsg = clasIDArray [0];
					chatTouserID = clasIDArray [1];
				}



				// Create a PendingIntent; we're only using one PendingIntent (ID = 0):
				const int pendingIntentId = 0;
				PendingIntent pendingIntent = 
					PendingIntent.GetActivity ( MainActivity.GetMainActivity() , pendingIntentId, intent, PendingIntentFlags.OneShot);

				// Instantiate the builder and set notification elements:
				Notification.Builder builder = new Notification.Builder(MainActivity.GetMainActivity())
					.SetContentTitle(title)
					.SetContentText(chatMsg)
					.SetDefaults(NotificationDefaults.Sound)
					.SetAutoCancel( true )
					.SetSmallIcon(Resource.Drawable.app_icon);

				builder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);

				if( handleClickNeeded )
					builder.SetContentIntent( pendingIntent );

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

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

				// Publish the notification:
				const int notificationId = 0;
				notificationManager.Notify(notificationId, notification);
			} 
			catch (Exception ex)
			{
				string err = ex.Message;
			}

		}
Example #18
0
		protected override async void OnHandleIntent(Android.Content.Intent intent)
		{
			//Console.WriteLine("[{0}] Received an intent: {1}", TAG, intent);

			ConnectivityManager cm = (ConnectivityManager)GetSystemService(Context.ConnectivityService);
			bool isNetworkAvailable = cm.BackgroundDataSetting && cm.ActiveNetworkInfo != null;
			if (!isNetworkAvailable) 
				return;

			ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
			string query = prefs.GetString(FlickrFetchr.PREF_SEARCH_QUERY, null);
			string lastResultId = prefs.GetString(FlickrFetchr.PREF_LAST_RESULT_ID, null);

			List<GalleryItem> items;
			if (query != null) {
				items = await new FlickrFetchr().Search(query);
			}
			else {
				items = await new FlickrFetchr().Fetchitems();
			}

			if (items.Count == 0)
				return;

			string resultId = items[0].Id;

			if (!resultId.Equals(lastResultId)) {
				//Console.WriteLine("[{0}] Got a new result: {1}", TAG, resultId);

				PendingIntent pi = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(PhotoGalleryActivity)), 0);

				Notification notification = new Notification.Builder(this)
					.SetTicker(Resources.GetString(Resource.String.new_pictures_title))
					.SetSmallIcon(Android.Resource.Drawable.IcMenuGallery)
					.SetContentTitle(Resources.GetString(Resource.String.new_pictures_title))
					.SetContentText(Resources.GetString(Resource.String.new_pictures_text))
					.SetContentIntent(pi)
					.SetAutoCancel(true)
					.Build();

				// Doesn't pay attention to if the app is already in the foreground
//				NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);
//				notificationManager.Notify(0, notification);
//				SendBroadcast(new Intent(ACTION_SHOW_NOTIFICATION), PERM_PRIVATE);

				// Only get notification when app is in background
				ShowBackgroundNotification(0, notification);

			}
			else {
				//Console.WriteLine("[{0}] Got an old result: {1}", TAG, resultId);
			}

			prefs.Edit().PutString(FlickrFetchr.PREF_LAST_RESULT_ID, resultId).Commit();
		}
      private Notification createNativeNotification(int badgeNumber, string title)
      {
          var builder = new Notification.Builder(Application.Context)
              .SetContentTitle(title)
              .SetTicker(title)
              .SetNumber(badgeNumber)
              .SetSmallIcon(Resource.Drawable.IcDialogEmail);

          var nativeNotification = builder.Build();
          return nativeNotification;
      }
        private Notification createNativeNotification(LocalNotification notification)
        {
            var builder = new Notification.Builder(Application.Context)
                .SetContentTitle(notification.Title)
                .SetContentText(notification.Text)
//                .SetSmallIcon(Resource.Drawable.IcDialogEmail);
                .SetSmallIcon(Application.Context.ApplicationInfo.Icon);

            var nativeNotification = builder.Build();
            return nativeNotification;
        }
		// Creates a new notification with a different visibility level.
		public Notification CreateNotification(NotificationVisibility visibility)
		{
			var builder = new Notification.Builder (Activity)
				.SetContentTitle ("Notification for Visibility metadata");

			builder.SetVisibility (visibility);
			builder.SetContentText (string.Format ("Visibility : {0}", 
				NotificationVisibilities.GetDescription(visibility)));
			builder.SetSmallIcon (NotificationVisibilities.GetNotificationIconId (visibility));
			return builder.Build ();
		}
 public AmpacheNotifications(Context context, AmpacheModel model)
 {
     _model = model;
     _context = context;
     _model.PropertyChanged += Handle_modelPropertyChanged;
     _builder = new Notification.Builder(context)
         .SetSmallIcon(Resource.Drawable.ic_stat_notify_musicplayer)
         .SetContentTitle("Ampache.NET")
         .SetContentIntent(PendingIntent.GetActivity(_context, 0, new Intent(_context, typeof(NowPlaying)), PendingIntentFlags.UpdateCurrent));
     ((NotificationManager)_context.GetSystemService(Context.NotificationService)).CancelAll();
 }
Example #23
0
		public static void CancelNotification(Activity activity)
		{
			try
			{
				NotificationManager notificationManager =
					activity.GetSystemService (Context.NotificationService) as NotificationManager;
				notificationManager.Cancel(notificationId);
				builder = null;
			}
			catch (Exception e) {
				Console.WriteLine (e.Message);
			}
		}
        /// <summary>
        /// Show a local notification in the Notification Area and Drawer.
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        public void Show(string title, string body)
        {
            var builder = new Notification.Builder(Application.Context);
            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetSmallIcon(Resource.Drawable.Icon);

            var notification = builder.Build();

            var manager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            manager.Notify(0, notification);
        }
		public override void OnPeerDisconnected (INode p0)
		{
			Notification.Builder notificationBuilder = new Notification.Builder (this)
				.SetContentTitle ("Forgetting Something?")
				.SetContentText ("You may have left your phone behind.")
				.SetVibrate (new long[]{ 0, 200 })
				.SetSmallIcon (Resource.Drawable.ic_launcher)
				.SetLocalOnly (true)
				.SetPriority ((int)NotificationPriority.Max);
			Notification card = notificationBuilder.Build ();
			((NotificationManager)GetSystemService (NotificationService))
				.Notify (FORGOT_PHONE_NOTIFICATION_ID, card);
		}
Example #26
0
        void SendNotification(string message)
        {
            var intent = new Intent(this, typeof(MainActivity));
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new Notification.Builder(this)
                                                      .SetContentTitle(TITLE)
                                                      .SetContentText(message)
                                                      .SetSmallIcon(Resource.Drawable.icon)
                                                      .SetContentIntent(pendingIntent);

            var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
            notificationManager.Notify(0, notificationBuilder.Build());
        }
        public void Notification()
        {
            Intent intent = new Intent(Forms.Context, typeof(MainActivity));

            Notification notification = new Notification.Builder(Forms.Context)
                .SetContentTitle("Dolce Timer")
                .SetContentText("Sua bebida estĆ” Pronta!")
                .SetSmallIcon(Resource.Drawable.coffee2)
                .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate).Build();

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

            notificationManager.Notify(1000, notification);
        }
        public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId)
        {
            // Instantiate the builder and set notification elements:
            notificationBuilder = new Notification.Builder (this)
                .SetContentTitle ("Test Notification")
                .SetContentText ("This worked")
                .SetSmallIcon (Resource.Drawable.vbclogo);

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

            ParsePush.ParsePushNotificationReceived += ParsePush_ParsePushNotificationReceived;

                return StartCommandResult.Sticky;
        }
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button> (Resource.Id.myButton);
			Button button1 = FindViewById<Button> (Resource.Id.button1);

			// Instantiate the builder and set notification elements:
			builder = new Notification.Builder (this)
				.SetContentTitle ("Test")
				.SetContentText ("This is test")
				.SetSmallIcon (Resource.Drawable.Icon);

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

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

			const int notificationId = 0;

			button.Click += delegate {
				// Publish the notification:
				notificationManger.Notify (notificationId,notification);
				button.Text = string.Format ("{0} clicks!", count++);
			};

			button1.Click += delegate {
				builder = new Notification.Builder (this)
					.SetContentTitle ("Updated Test")
					.SetContentText ("This is updated test")
					.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate)
					.SetSmallIcon (Resource.Drawable.Icon);

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

				// Publish the notification:
				notificationManger.Notify (notificationId,notification);

				button.Text = string.Format ("{0} clicks!", count++);
			};
		}
		void BuildWearableOnlyNotification (string title, string content, bool withDismissal)
		{
			var builder = new Notification.Builder (this)
				.SetSmallIcon (Resource.Drawable.ic_launcher)
				.SetContentTitle (title)
				.SetContentText (content);

			if (withDismissal) {
				var dismissIntent = new Intent (Constants.ActionDismiss);
				dismissIntent.PutExtra (Constants.KeyNotificationId, Constants.BothId);
				PendingIntent pendingIntent = PendingIntent.GetService (this, 0, dismissIntent, PendingIntentFlags.UpdateCurrent);
				builder.SetDeleteIntent (pendingIntent);
			}

			((NotificationManager)GetSystemService (NotificationService)).Notify (Constants.WatchOnlyId, builder.Build ());
		}
Example #31
0
        void CreateNotification(string title, string desc)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            intent.PutExtra("id", "holo");
            var pendingIntent       = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);
            var notificationBuilder = new Notification.Builder(this)
                                      .SetContentTitle("Yooin")
                                      .SetContentText(desc)
                                      .SetAutoCancel(true)
                                      .SetNumber(2)
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm))
                                      .SetSmallIcon(Resource.Drawable.abc_btn_check_material)
                                      .SetDefaults(NotificationDefaults.Vibrate);


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

            notificationManager.Notify(0, notificationBuilder.Build());
        }
Example #32
0
        private void SendLevel3Alert()
        {
            if (McolAlertsFragment.Level3Notify)
            {
                const int Level3NotificationId = 1000;

                //Create SMS intent and pass in username
                Intent smsIntent = new Intent(this, typeof(SMSActivity));

                /// Construct a back stack for cross-task navigation:
                TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
                stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(SMSActivity)));
                stackBuilder.AddNextIntent(smsIntent);

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

                //Big text style notification
                string longMessage = "MCOL level 3 alerts are present. Click this notification to notify other team members.";

                Notification notif = new Notification.Builder(this)
                                     .SetContentTitle("Warning: Level 3 Alerts")
                                     .SetVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                                     .SetContentIntent(resultPendingIntent)
                                     .SetSmallIcon(Resource.Drawable.Icon)
                                     .SetStyle(new Notification.BigTextStyle()
                                               .BigText(longMessage))
                                     .Build();

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

                //Once notified we can stop sending alert for this session
                McolAlertsFragment.AlreadyNotified = true;
            }
        }
Example #33
0
        private void BtnNotify_Click(object sender, EventArgs e)
        {
            //Intent intent = new Intent(this, typeof(MainActivity));
            //const int pendingIntentId = 0;
            //PendingIntent pendingIntent =
            //    PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);

            Notification.Builder builder = new Notification.Builder(this);
            //builder.SetContentIntent(pendingIntent);
            builder.SetPriority((int)NotificationPriority.High);
            builder.SetContentTitle("ģ•Œė ¤ė“œė¦½ė‹ˆė‹¤!!");
            builder.SetContentText("Hello World! This is my first notification!");
            builder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate | NotificationDefaults.Lights);
            builder.SetSmallIcon(Resource.Drawable.Icon);
            Notification noti = builder.Build();

            // Build the notification:
            Notification        notification = builder.Build();
            NotificationManager manager      = GetSystemService(Context.NotificationService) as NotificationManager;

            manager.Notify(101, noti);
        }
        // Creates a new notification depending on makeHeadsUpNotification.
        // If makeHeadsUpNotification is true, the notifications will be
        // Heads-Up Notifications.
        public Notification CreateNotification(bool makeHeadsUpNotification)
        {
            var builder = new Notification.Builder(Activity)
                          .SetSmallIcon(Resource.Drawable.ic_launcher_notification)
                          .SetPriority((int)NotificationPriority.Default)
                          .SetCategory(Notification.CategoryMessage)
                          .SetContentTitle("Sample Notification")
                          .SetContentText("This is a normal notification.");

            if (makeHeadsUpNotification)
            {
                var push = new Intent();
                push.AddFlags(ActivityFlags.NewTask);
                push.SetClass(Activity, Java.Lang.Class.FromType(typeof(MainActivity)));
                var fullScreenPendingIntent = PendingIntent.GetActivity(Activity, 0,
                                                                        push, PendingIntentFlags.CancelCurrent);
                builder
                .SetContentText("Heads-Up Notification on Android L or above.")
                .SetFullScreenIntent(fullScreenPendingIntent, true);
            }
            return(builder.Build());
        }
        public void HandleNotification(string title, string msg)
        {
            var n = new Notification.Builder(Forms.Context);

            n.SetSmallIcon(Resource.Drawable.notification_template_icon_bg);
            n.SetLights(Android.Graphics.Color.Blue, 300, 1000);
            //n.SetContentIntent(pendingIntent);
            n.SetContentTitle(title);
            n.SetTicker(msg);
            //n.SetLargeIcon(global::Android.Graphics.BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon));
            n.SetAutoCancel(true);
            n.SetContentText(msg);
            n.SetVibrate(new long[] {
                200,
                200,
                100,
            });

            var nm = NotificationManager.FromContext(Forms.Context);

            nm.Notify(0, n.Build());
        }
Example #36
0
        public override void OnCreate()
        {
            _deliverService = new MessageDeliverService(new DeviceInformation("My Xperia", Guid.Parse(PUBLISHER_ID)));

            _sender = new MailSender()
            {
                ServerName  = "smtp-mail.outlook.com",
                Port        = 587,
                FromAddress = "*****@*****.**",
                ToAddress   = "*****@*****.**",
                Password    = "******"
            };

            _builder = new Notification.Builder(this)
                       .SetContentText(_sender.ToAddress)
                       .SetSmallIcon(Resource.Drawable.ic_dialog_email)
                       .SetOngoing(true);

            _handler = new Handler(new Action <Message>(OnIntentHandled));

            base.OnCreate();
        }
Example #37
0
        /// <summary>
        /// Send local notification
        /// </summary>
        private void SendLocalNotication(string messageBody, IDictionary <string, string> data)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            foreach (string key in data.Keys)
            {
                intent.PutExtra(key, data[key]);
            }
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var builder = new Notification.Builder(this)
                          .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
                          .SetContentTitle("Firebase message")
                          .SetContentText(messageBody)
                          .SetAutoCancel(true)
                          .SetContentIntent(pendingIntent);

            var manager = NotificationManager.FromContext(this);

            manager.Notify(0, builder.Build());
        }
        /*
         * Create builder and assign title and text to the notification
         */
        public Notification.Builder CreateNotificationBuilder(string title, string content)
        {
            Notification.Builder builder = null;

            //if version is lower than Android O, priority has to be set manually
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                builder = new Notification.Builder(CrossCurrentActivity.Current.Activity.ApplicationContext, "Location-based information");
            }
            else
            {
                builder = new Notification.Builder(CrossCurrentActivity.Current.Activity.ApplicationContext, "Location-based information");
                int priority = (int)NotificationPriority.High;
                builder.SetPriority(priority);
            }
            var context = CrossCurrentActivity.Current.AppContext;

            builder.SetContentTitle(title);
            builder.SetContentText(content);
            builder.SetSmallIcon(Resource.Drawable.Notification_Icon);
            return(builder);
        }
Example #39
0
        /// <summary>
        /// äø‹č½½
        /// </summary>
        /// <param name="url">äø‹č½½ę–‡ä»¶ēš„URL地址</param>
        /// <param name="exterName">äæå­˜åˆ°ęœ¬åœ°ēš„ę–‡ä»¶ę‰©å±•å</param>
        /// <returns></returns>
        public void DownLoadFile(string url, string exterName)
        {
            try
            {
                // Instantiate the builder and set notification elements:
                builder = new Notification.Builder(Application.Context.ApplicationContext);
                // Build the notification:
                notification = builder.Build();
                contentView  = new RemoteViews(Application.Context.PackageName, Resource.Layout.progress_notify);
                // Get the notification manager:
                notificationManager =
                    Application.Context.ApplicationContext.GetSystemService(Context.NotificationService) as NotificationManager;


                string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                string localFilename = DateTime.Now.ToString("yyyyMMddHHmmss") + exterName;

                fileLocalPath = System.IO.Path.Combine(GetPath().Path, localFilename);
                WebClient webClient = new WebClient();

                try
                {
                    webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
                    webClient.DownloadFileCompleted   += WebClient_DownloadFileCompleted;
                    Task.Factory.StartNew(() => { webClient.DownloadFileAsync(new Uri(url), fileLocalPath); });
                }
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (System.Exception)
                {
                    return;
                }
            }
            catch (Exception)
            {
            }
        }
Example #40
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);

            var pendingIntent       = PendingIntent.GetActivity(this, NOTIFICATION_ID, intent, PendingIntentFlags.OneShot);
            var messageNotification = new MessageNotification(message);

            Notification notification;

            if (_useNotificationChannel)
            {
                notification = new Notification.Builder(this, CHANNEL_ID)
                               .SetSmallIcon(SmallIcon)
                               .SetLargeIcon(LargeIcon)
                               .SetContentTitle(messageNotification.Title)
                               .SetContentText(messageNotification.Body)
                               .SetAutoCancel(true)
                               .SetContentIntent(pendingIntent)
                               .Build();
            }
            else
            {
                notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                               .SetSmallIcon(SmallIcon)
                               .SetLargeIcon(LargeIcon)
                               .SetContentTitle(messageNotification.Title)
                               .SetContentText(messageNotification.Body)
                               .SetAutoCancel(true)
                               .SetContentIntent(pendingIntent)
                               .SetLights(LightColour, LightOnMs, LightOffMs)
                               .SetSound(Ringtone)
                               .SetVibrate(VibrationPattern)
                               .Build();
            }

            _notificationManager.Notify(NOTIFICATION_ID, notification);
        }
Example #41
0
        private void StartForeground()
        {
            //Intent for showing notification
            var pendingIntent = PendingIntent.GetActivity(ApplicationContext, 0,
                                                          new Intent(ApplicationContext, typeof(MainActivity)),
                                                          PendingIntentFlags.UpdateCurrent);

            //Custom notification and build it
            var builder = new Notification.Builder(this)
                          .SetContentText("Radio is playing")
                          .SetContentTitle("Listen Radio")
                          .SetContentIntent(pendingIntent)
                          .SetSmallIcon(Resource.Drawable.Icon)
                          .SetOngoing(true);
            Notification notification = builder.Build();

            //Init notification manager and show notification
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(NotificationId, notification);
        }
        private void addNotification()
        {
            // create the pending intent and add to the notification
            var intent = this.PackageManager.GetLaunchIntentForPackage(this.PackageName); // opens app from background ( Can we use this auto open app with alert? )
                                                                                          // intent.AddFlags(ActivityFlags.ClearTop);
                                                                                          //Intent intent = new Intent(this, typeof(BackgroundService));
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);
            var           lastLogin     = "******";

            // string lastLogin =  as string;
            if (Xamarin.Forms.Application.Current.Properties.Count > 0)
            {
                if (Xamarin.Forms.Application.Current.Properties[Constants.CURRENT_DATE] != null)
                {
                    lastLogin = "******" + Xamarin.Forms.Application.Current.Properties[Constants.CURRENT_DATE].ToString();
                }
            }
            string deviceModel = DeviceModal;

            Xamarin.Forms.Application.Current.Properties[Constants.DEVICE_MODEL] = deviceModel;

            // create the notification
            Notification.Builder m_notificationBuilder = new Notification.Builder(this)
                                                         .SetContentTitle("AssetChain")
                                                         .SetContentText(lastLogin)
                                                         .SetSmallIcon(Resource.Drawable.logo)
                                                         .SetContentIntent(pendingIntent);

            Notification notification = m_notificationBuilder.Build();

            notification.Flags = NotificationFlags.AutoCancel;

            // send the notification
            const int           NOTIFICATION_ID     = 101;
            NotificationManager notificationManager = this.GetSystemService(Context.NotificationService) as NotificationManager;

            StartForeground(NOTIFICATION_ID, notification); // locks notificaion in bar
            notificationManager.Notify(NOTIFICATION_ID, m_notificationBuilder.Build());
        }
        private void addNewTaskmethod(object sender, EventArgs e)
        {
            // insert task into database
            String   task = taskEdtTxt.Text;
            DateTime now  = DateTime.Now;


            dbHelper.InsertNewTask(task, now.ToString("F"));


            // Creating a Notification Channel for Android 8.0 Oreo
            string chanName          = "Urgent";
            var    importance        = NotificationImportance.High;
            NotificationChannel chan = new NotificationChannel(URGENT_CHANNEL, chanName, importance);

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


            // Submit the notification channel object to the notification manager
            NotificationManager notificationManager =
                (NotificationManager)GetSystemService(NotificationService);

            notificationManager.CreateNotificationChannel(chan);

            // Posting to a Notifications Channel
            Notification.Builder builder = new Notification.Builder(this)
                                           .SetContentTitle("Attention!")
                                           .SetSmallIcon(Resource.Drawable.logoo)
                                           .SetContentText("A new Task has created successfully")
                                           .SetChannelId(URGENT_CHANNEL);

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

            Intent i = new Intent(this, typeof(MainActivity));

            StartActivity(i);
        }
Example #44
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            // Code not directly related to publishing the notification has been omitted for clarity.
            // Normally, this method would hold the code to be run when the service is started.


            int    i    = 0;
            string val1 = string.Empty;
            string val2 = string.Empty;

            if (val == 0)
            {
                new Task(() =>
                {
                    Plugin.Connectivity.CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;
                }).Start();
            }
            builder = new Notification.Builder(this);
            builder.SetContentTitle("Nokcoot");
            builder.SetContentText("Offline drafts");
            notification = builder.Build();
            //.SetContentTitle("Nokcoot")
            ////.SetContentText("Offline drafts uploaded")
            ////.SetSmallIcon(Resource.Drawable.icon)
            ////.SetDefaults(NotificationDefaults.Sound)
            //.SetAutoCancel(true)
            //.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
            //////  .SetContentIntent(BuildIntentToShowMainActivity())
            ////.SetOngoing(true)
            ////.AddAction(BuildRestartTimerAction())
            //// .AddAction(BuildStopServiceAction())
            //.Build();

            // Enlist this instance of the service as a foreground service
            // StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification);
            StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification);
            return(StartCommandResult.Sticky);
        }
Example #45
0
        private void PopUpNotification(int id, string title, string message)
        {
            Notification.Builder mBuilder =
                new Notification.Builder(this)
                .SetSmallIcon(Resource.Drawable.ic_notification)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetAutoCancel(true);
            // Creates an explicit intent for an Activity in your app
            Intent resultIntent = new Intent(this, typeof(MainActivity));

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            // The stack builder object will contain an artificial back stack for the
            // started Activity.
            // This ensures that navigating backward from the Activity leads out of
            // your application to the Home screen.
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            // Adds the back stack for the Intent (but not the Intent itself)
            //stackBuilder.AddParentStack();
            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.AddNextIntent(resultIntent);
            PendingIntent resultPendingIntent =
                stackBuilder.GetPendingIntent(
                    0,
                    PendingIntentFlags.UpdateCurrent
                    );

            mBuilder.SetContentIntent(resultPendingIntent);



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

            // mId allows you to update the notification later on.
            mNotificationManager.Notify(id, mBuilder.Build());
        }
Example #46
0
        //check if goal near deadline
        public void CheckUpdate()
        {
            DateTime current = DateTime.Now;
            int      z       = ShoppingCollection.CheckItem(current).Count;

            Console.WriteLine("Shopping service: " + z);

            //Toast.MakeText(this, "Shopping lists count: " + z, ToastLength.Long).Show();

            //while (i < z)
            //{
            //    string title = ShoppingCollection.CheckItem(current)[i].ListTitle;

            //    Toast.MakeText(this, "Shopping lists today: " + title, ToastLength.Long).Show();
            //}

            Thread t = new Thread(() =>
            {
                Thread.Sleep(1000);
                if (ShoppingCollection.CheckItem(DateTime.Now).Count > 0)
                {
                    var nMgr = (NotificationManager)GetSystemService(NotificationService);

                    //Details of notification in previous recipe
                    Notification.Builder builder = new Notification.Builder(this)
                                                   .SetAutoCancel(true)
                                                   .SetContentTitle("Shopping Day")
                                                   .SetNumber(notifyId)
                                                   .SetContentText("You have got some shopping to do today.")
                                                   .SetVibrate(new long[] { 100, 200, 300 })
                                                   .SetSmallIcon(Resource.Drawable.ic_cart);

                    nMgr.Notify(0, builder.Build());
                }
            });

            t.Start();
        }
Example #47
0
        //used to generate local notifications for remote messages
        void SendNotification(Dictionary <string, string> response)
        {
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
            Intent           wklIntent    = new Intent(this, typeof(WorkListActivity));

            stackBuilder.AddNextIntent(wklIntent);

            PendingIntent pendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.OneShot);  //id=0

            Notification.BigTextStyle style = new Notification.BigTextStyle();
            style.BigText(response["MSG_CONTENT"]);
            style.SetSummaryText(response["MSG_TITLE"]);

            Notification.Builder builder = new Notification.Builder(Application.Context)
                                           .SetContentTitle("PeoplePlus Notification")
                                           .SetContentText("Pending Task(s) in your WorkList Viewer")
                                           .SetSmallIcon(Resource.Drawable.neptunelogo)
                                           .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.neptunelogo))
                                           .SetAutoCancel(true)
                                           .SetContentIntent(pendingIntent);

            if ((int)Build.VERSION.SdkInt >= 21)
            {
                builder.SetVisibility(NotificationVisibility.Private)
                .SetCategory(Notification.CategoryAlarm)
                .SetCategory(Notification.CategoryCall)
                .SetStyle(style);
            }

            builder.SetPriority((int)NotificationPriority.High);
            builder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);

            Notification notification = builder.Build();

            NotificationManager notificationManager = GetSystemService(NotificationService) as NotificationManager;

            notificationManager.Notify(0, notification);
        }
        private async void ValidateJC()
        {
            var miCorreo    = FindViewById <EditText>(Resource.Id.txtEmail);
            var miPassword  = FindViewById <EditText>(Resource.Id.txtPassword);
            var miResultado = FindViewById <TextView>(Resource.Id.lbValidateResult);

            string StudentEmail    = miCorreo.Text.Trim();
            string PasswordStudent = miPassword.Text.Trim();
            string resultadoFin    = "";

            string myDevice = Android.Provider.Settings.Secure.GetString(
                ContentResolver,
                Android.Provider.Settings.Secure.AndroidId);

            var ServiceClient = new SALLab07.ServiceClient();
            var Result        = await ServiceClient.ValidateAsync(StudentEmail, PasswordStudent, myDevice);

            resultadoFin     = $"{Result.Status}\n{Result.Fullname}\n{Result.Token}"; //resultadoFin = "prueba";
            miResultado.Text = "";

            if ((Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop))
            {
                var Builder = new Notification.Builder(this)
                              .SetContentTitle("Validacion de Actividad")
                              .SetContentText(resultadoFin) //resultadoFin
                              .SetSmallIcon(Resource.Drawable.Icon);

                Builder.SetCategory(Notification.CategoryMessage);
                var ObjectNotification = Builder.Build();
                var Manager            = GetSystemService(
                    Android.Content.Context.NotificationService) as NotificationManager;
                Manager.Notify(0, ObjectNotification);
            }
            else
            {
                miResultado.Text = resultadoFin;
            }
        }
Example #49
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            //Getting Notification Service
            mManager = (NotificationManager)this.BaseContext.ApplicationContext
                       .GetSystemService(NotificationService);

            /*
             * When the user taps the notification we have to show the Home Screen
             * of our App, this job can be done with the help of the following
             * Intent.
             */
            Intent intent1 = new Intent(this.BaseContext.ApplicationContext, typeof(MainActivity));

            intent1.AddFlags(ActivityFlags.SingleTop
                             | ActivityFlags.ClearTop);

            PendingIntent pendingNotificationIntent = PendingIntent.GetActivity(
                Android.App.Application.Context.ApplicationContext, 0, intent1,
                PendingIntentFlags.UpdateCurrent);

            Notification.Builder builder = new Notification.Builder(this);

            builder.SetAutoCancel(true);
            //builder.SetTicker("this is ticker text");
            builder.SetContentTitle("TimeSheet");
            builder.SetContentText("Remember input your timesheet ;)");
            builder.SetSmallIcon(Resource.Drawable.logo);
            builder.SetContentIntent(pendingNotificationIntent);
            //builder.SetOngoing(true);
            //setBadgeIconType(1);
            //builder.SetSubText("This is subtext...");   //API level 16
            builder.SetNumber(100);
            var notification = builder.Build();

            mManager.Notify(0, notification);

            return(base.OnStartCommand(intent, flags, startId));
        }
        /// <summary>
        /// Issues the notification.
        /// </summary>
        /// <param name="title">Title.</param>
        /// <param name="message">Message.</param>
        /// <param name="id">Identifier of notification.</param>
        /// <param name="protocolId">Protocol identifier to check for alert exclusion time windows.</param>
        /// <param name="alertUser">If set to <c>true</c> alert user.</param>
        /// <param name="displayPage">Display page.</param>
        public override void IssueNotificationAsync(string title, string message, string id, string protocolId, bool alertUser, DisplayPage displayPage)
        {
            if (_notificationManager == null)
            {
                return;
            }

            Task.Run(() =>
            {
                if (message == null)
                {
                    CancelNotification(id);
                }
                else
                {
                    Intent notificationIntent = new Intent(_service, typeof(AndroidSensusService));
                    notificationIntent.PutExtra(DISPLAY_PAGE_KEY, displayPage.ToString());

                    PendingIntent notificationPendingIntent = PendingIntent.GetService(_service, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

                    Notification.Builder notificationBuilder = new Notification.Builder(_service)
                                                               .SetContentTitle(title)
                                                               .SetContentText(message)
                                                               .SetSmallIcon(Resource.Drawable.ic_launcher)
                                                               .SetContentIntent(notificationPendingIntent)
                                                               .SetAutoCancel(true)
                                                               .SetOngoing(false);

                    if (alertUser && !Protocol.TimeIsWithinAlertExclusionWindow(protocolId, DateTime.Now.TimeOfDay))
                    {
                        notificationBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
                        notificationBuilder.SetVibrate(new long[] { 0, 250, 50, 250 });
                    }

                    _notificationManager.Notify(id, 0, notificationBuilder.Build());
                }
            });
        }
Example #51
0
        public static void SendNotification(string title, string message)
        {
                        #if __ANDROID__
            // Instantia
            Notification.Builder builder = new Notification.Builder(Application.Context)
                                           .SetContentTitle(title)
                                           .SetContentText(message)
                                           .SetSmallIcon(Android.Resource.Drawable.IcDialogMap);

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

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

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

                        #if __IOS__
            // create the notification
            UILocalNotification notification = new UILocalNotification();

            // configure the alert
            notification.AlertAction = title;
            notification.AlertBody   = message;

            // modify the badge
            notification.ApplicationIconBadgeNumber = UIApplication.SharedApplication.ApplicationIconBadgeNumber + 1;

            // set the sound to be the default sound
            notification.SoundName = UILocalNotification.DefaultSoundName;

            // schedule it
            UIApplication.SharedApplication.PresentLocalNotificationNow(notification);
                        #endif
        }
Example #52
0
        public void ShowNotification(string title, string body, IEnumerable <BundleItem> bundleItems = null)
        {
            this.CreateNotificationChannel();

            var notificationId = random.Next();

            var builder = new Notification.Builder(Android.App.Application.Context, CHANNEL_ID);

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

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

            var valuesForActivity = this.GetBundle(bundleItems);

            //var resultIntent = GetLauncherActivity();
            var resultIntent = new Intent(Android.App.Application.Context, Class.FromType(typeof(MainActivity)));
            //resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);

            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Android.App.Application.Context);

            stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);
            resultIntent.PutExtras(valuesForActivity);
            var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            _manager.Notify(notificationId, builder.Build());
        }
Example #53
0
        private void RegisterForegroundService()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                string CHANNEL_ID = "default";
                var    channel    = new NotificationChannel(CHANNEL_ID, "Channel", NotificationImportance.Default)
                {
                    Description = "Foreground Service Channel"
                };

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

                var notification = new Notification.Builder(this, CHANNEL_ID)
                                   .SetContentTitle("NebliDex")
                                   .SetContentText("NebliDex is running")
                                   .SetSmallIcon(Resource.Drawable.icon)
                                   .SetContentIntent(BuildIntentToShowNebliDexUI())
                                   .SetOngoing(true)
                                   .Build();

                // Enlist this instance of the service as a foreground service
                StartForeground(FORSERVICE_NOTIFICATION_ID, notification);
            }
            else
            {
                var notification = new Notification.Builder(this)
                                   .SetContentTitle("NebliDex")
                                   .SetContentText("NebliDex is running")
                                   .SetSmallIcon(Resource.Drawable.icon)
                                   .SetContentIntent(BuildIntentToShowNebliDexUI())
                                   .SetOngoing(true)
                                   .Build();

                // Enlist this instance of the service as a foreground service
                StartForeground(FORSERVICE_NOTIFICATION_ID, notification);
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            Button   ValidarButton = FindViewById <Button>(Resource.Id.ValidarButton);
            EditText CorreoText    = FindViewById <EditText>(Resource.Id.CorreoText);
            EditText PasswordText  = FindViewById <EditText>(Resource.Id.PasswordText);
            TextView ResultadoText = FindViewById <TextView>(Resource.Id.ResultadoTextView);

            ValidarButton.Click += async(s, ev) =>
            {
                string deviceID = Android.Provider.Settings.Secure.GetString(ContentResolver,
                                                                             Android.Provider.Settings.Secure.AndroidId);
                ServiceClient serviceClient = new ServiceClient();
                ResultInfo    Resultado     = await serviceClient.ValidateAsync(CorreoText.Text,
                                                                                PasswordText.Text, deviceID);

                if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    string resultado = $"{Resultado.Status} {Resultado.Fullname} {Resultado.Token}";
                    var    Builder   = new Notification.Builder(this).SetContentTitle("ValidaciĆ³n de actividad")
                                       .SetContentText(resultado).SetSmallIcon(Resource.Drawable.Icon);

                    Builder.SetCategory(Notification.CategoryMessage);

                    var ObjectNotification = Builder.Build();
                    var Manager            = GetSystemService(Android.Content.Context.NotificationService) as NotificationManager;
                    Manager.Notify(0, ObjectNotification);
                }
                else
                {
                    string resultado = $"{Resultado.Status}\n{Resultado.Fullname}\n{Resultado.Token}";
                    ResultadoText.Text = resultado;
                }
            };
        }
Example #55
0
        private void CreateNotification(string title, string msg, string parameter = null)
        {
            var startupIntent = new Intent(this, typeof(MainActivity));

            startupIntent.PutExtra("param", parameter);

            var stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(startupIntent);

            var pendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.OneShot);
            var notification  = new Notification.Builder(this)
                                .SetContentIntent(pendingIntent)
                                .SetContentTitle(title)
                                .SetContentText(msg)
                                .SetSmallIcon(Resource.Drawable.icon)
                                .SetAutoCancel(true)
                                .Build();
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(0, notification);
        }
Example #56
0
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        private void StartForeground()
        {
            var pendingIntent = PendingIntent.GetActivity(ApplicationContext, 0,
                                                          new Intent(ApplicationContext, typeof(MainActivity)),
                                                          PendingIntentFlags.UpdateCurrent);


            // Instantiate the builder and set notification elements:
            var builder = new Notification.Builder(this)
                          .SetContentTitle("The Brewing Network")
                          .SetContentText(MediaTitle)
                          .SetSmallIcon(Resource.Drawable.hopgrenade);

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

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

            notificationManager?.Notify(NotificationId, notification);
            StartForeground(NotificationId, notification);
        }
        private void SetMetadata(Notification.Builder builder)
        {
            if ((int)Build.VERSION.SdkInt >= 16)
            {
                builder.SetPriority(highPriority.Checked ? (int)NotificationPriority.High : (int)NotificationPriority.Default);
            }

            if ((int)Build.VERSION.SdkInt >= (int)BuildVersionCodes.Lollipop)
            {
                builder.SetCategory(Notification.CategoryMessage);
                var visibility = NotificationVisibility.Public;
                if (spinner.SelectedItemPosition == 1)
                {
                    visibility = NotificationVisibility.Private;
                }
                else if (spinner.SelectedItemPosition == 2)
                {
                    visibility = NotificationVisibility.Secret;
                }

                builder.SetVisibility(visibility);
            }
        }
        public static void ShowNotification(string title, string message)
        {
            Context act    = ((Activity)MainActivity.Instance);
            Intent  intent = new Intent(act, typeof(MainActivity));

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

            Notification.Builder builder = new Notification.Builder(act)
                                           .SetContentIntent(pendingIntent)
                                           .SetContentTitle(title)
                                           .SetContentText(message)
                                           .SetSmallIcon(Resource.Drawable.Icon);

            Notification        notification        = builder.Build();
            NotificationManager notificationManager =
                act.GetSystemService(Context.NotificationService) as NotificationManager;
            const int notificationId = 0;

            notificationManager.Notify(notificationId, notification);
        }
Example #59
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            NotificationManager manager = (NotificationManager)GetSystemService(Context.NotificationService);

            Notification.Builder    builder  = BuildNormal();
            Notification.InboxStyle bigStyle = new Notification.InboxStyle(builder);

            manager.Notify(NOTIFY_ID, bigStyle.SetSummaryText("Summary Text Here")
                           .AddLine("Here is entry 1")
                           .AddLine("Here is entry 2")
                           .AddLine("Here is entry 3")
                           .AddLine("Here is entry 4")
                           .Build());

            Finish();
        }
        //Register the foreground service.
        void RegisterForegroundService(bool vibrate)
        {
            long[] vibrations = new long[] { 0, 0, 0, 0 };

            if (vibrate)
            {
                vibrations = new long[] { 0, 200, 200, 200 };
            }

            var notification = new Notification.Builder(this)
                               .SetContentTitle(Resources.GetString(Resource.String.app_name))
                               .SetContentText(notif_text)
                               .SetSmallIcon(Resource.Drawable.ic_notification_icon)
                               .SetContentIntent(BuildIntentToShowMainActivity())
                               .SetOngoing(true)
                               .SetVibrate(vibrations)
                               .AddAction(BuildStopServiceAction())
                               .Build();

            // Enlist this instance of the service as a foreground service

            StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification);
        }