예제 #1
0
        /// <summary>
        /// Builds the Notification.Action that will allow the user to stop the service via the
        /// notification in the status bar
        /// </summary>
        /// <returns>The stop service action.</returns>
        private Notification.Action BuildStopServiceAction()
        {
            var stopServiceIntent = new Intent(this, GetType());

            stopServiceIntent.SetAction(Constants.ActionStopService);
            var stopServicePendingIntent = PendingIntent.GetService(this, 0, stopServiceIntent, 0);

            var builder = new Notification.Action.Builder(Android.Resource.Drawable.IcMediaPause, "Stop Service", stopServicePendingIntent);

            return(builder.Build());
        }
예제 #2
0
        /// <summary>
        /// Builds a Notification.Action that will instruct the service to restart the timer.
        /// </summary>
        /// <returns>The restart timer action.</returns>
        private Notification.Action BuildRestartTimerAction()
        {
            var restartTimerIntent = new Intent(this, GetType());

            restartTimerIntent.SetAction(Constants.ActionRestartTimer);
            var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

            var builder = new Notification.Action.Builder(Android.Resource.Drawable.EditText, "Restart Timer", restartTimerPendingIntent);

            return(builder.Build());
        }
예제 #3
0
        /// <summary>
        /// Builds the ability to stop the TrackingService by pressing the "Stop Tracking" button on the notification
        /// </summary>
        /// <returns></returns>
        Notification.Action BuildStopServiceAction()
        {
            var stopServiceIntent = new Intent(this, GetType());

            stopServiceIntent.SetAction("TheOxbridgeApp.action.STOP_SERVICE");
            var stopServicePendingIntent = PendingIntent.GetService(this, 0, stopServiceIntent, 0);

            var builder = new Notification.Action.Builder(Android.Resource.Drawable.IcMediaPause, "Stop tracking", stopServicePendingIntent);

            return(builder.Build());
        }
예제 #4
0
        /// <summary>
        /// Builds a Notification.Action that will instruct the service to restart the timer.
        /// </summary>
        /// <returns>The restart timer action.</returns>
        Notification.Action BuildRestartTimerAction()
        {
            var restartTimerIntent = new Intent(this, GetType());

            restartTimerIntent.SetAction(Constants.ACTION_RESTART_TIMER);
            var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

            var builder = new Notification.Action.Builder(HaxOnTheWay.Droid.Resource.Drawable.ic_action_restart_timer,
                                                          GetText(HaxOnTheWay.Droid.Resource.String.restart_timer),
                                                          restartTimerPendingIntent);

            return(builder.Build());
        }
예제 #5
0
        /// <summary>
        /// Запускает действие, которое позволяет завершить работу сервиса
        /// </summary>
        /// <returns>Действие завершения сервиса</returns>
        Notification.Action BuildStopServiceAction()
        {
            var stopServiceIntent = new Intent(this, GetType());

            stopServiceIntent.SetAction("MyNotes.action.STOP_SERVICE");
            var stopServicePendingIntent = PendingIntent.GetService(this, 0, stopServiceIntent, 0);

            var builder = new Notification.Action.Builder(Android.Resource.Drawable.IcMediaPause,
                                                          GetText(Resource.String.stop_service),
                                                          stopServicePendingIntent);

            return(builder.Build());
        }
예제 #6
0
        Notification.Action BuildTestAction()
        {
            var restartTimerIntent = new Intent(this, GetType());

            restartTimerIntent.SetAction("ACTION_TEST");
            var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

            var builder = new Notification.Action.Builder(Resource.Drawable.abc_btn_check_material,
                                                          "Ttttest",
                                                          restartTimerPendingIntent);

            return(builder.Build());
        }
예제 #7
0
        /// <summary>
        /// Builds a Notification.Action that will instruct the service to restart the timer.
        /// </summary>
        /// <returns>The restart timer action.</returns>
        Notification.Action BuildRestartTimerAction()
        {
            var restartTimerIntent = new Intent(this, GetType());

            restartTimerIntent.SetAction(Constants.ACTION_RESTART_TIMER);
            var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

            var builder = new Notification.Action.Builder(Resource.Mipmap.ic_launcher,
                                                          GetText(Resource.String.restart_timestamp_service_button_text),
                                                          restartTimerPendingIntent);

            return(builder.Build());
        }
예제 #8
0
        /// <summary>
        /// Builds the Notification.Action that will allow the user to stop the service via the
        /// notification in the status bar
        /// </summary>
        /// <returns>The stop service action.</returns>
        Notification.Action BuildStopServiceAction()
        {
            var stopServiceIntent = new Intent(this, GetType());

            stopServiceIntent.SetAction(Constants.ACTION_STOP_SERVICE);
            var stopServicePendingIntent = PendingIntent.GetService(this, 0, stopServiceIntent, 0);

            var builder = new Notification.Action.Builder(Android.Resource.Drawable.IcMediaPause,
                                                          GetText(HaxOnTheWay.Droid.Resource.String.stop_service),
                                                          stopServicePendingIntent);

            return(builder.Build());
        }
예제 #9
0
        /// <summary>
        /// Builds a Notification.Action that will instruct the service to restart the timer.
        /// </summary>
        /// <returns>The restart timer action.</returns>
        Notification.Action BuildRestartTimerAction()
        {
            var restartTimerIntent = new Intent(this, GetType());

            restartTimerIntent.SetAction(Constants.ACTION_RESTART_TIMER);
            var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

            var builder = new Notification.Action.Builder(Resource.Drawable.ic_mtrl_chip_checked_circle,
                                                          "Restart",
                                                          restartTimerPendingIntent);

            return(builder.Build());
        }
예제 #10
0
        //      /// <summary>
        ///// Builds a PendingIntent that will display the main activity of the app. This is used when the
        ///// user taps on the notification; it will take them to the main activity of the app.
        ///// </summary>
        ///// <returns>The content intent.</returns>
        //PendingIntent BuildIntentToShowMainActivity()
        //      {
        //          var notificationIntent = new Intent(this, typeof(MainActivity));
        //          notificationIntent.SetAction("ServicesDemo3.action.MAIN_ACTIVITY");
        //          notificationIntent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTask);
        //          notificationIntent.PutExtra("has_service_been_started", true);

        //          var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
        //          return pendingIntent;
        //      }

        /// <summary>
        /// Builds a Notification.Action that will instruct the service to restart the timer.
        /// </summary>
        /// <returns>The restart timer action.</returns>
        private Notification.Action StopTimerAction()
        {
            var restartTimerIntent = new Intent(this, GetType());

            restartTimerIntent.SetAction("STOP_TIMER");
            var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

            var builder = new Notification.Action.Builder(Resource.Drawable.ic_action_stop,
                                                          GetText(Resource.String.stop),
                                                          restartTimerPendingIntent);

            return(builder.Build());
        }
        /// <summary>
        /// Builds the Notification.Action that will allow the user to stop the service via the
        /// notification in the status bar
        /// </summary>
        /// <returns>The stop service action.</returns>
        Notification.Action BuildStopServiceAction()
        {
            var stopServiceIntent = new Intent(this, GetType());

            stopServiceIntent.SetAction(Constants.ACTION_STOP_SERVICE);
            var stopServicePendingIntent = PendingIntent.GetService(this, 0, stopServiceIntent, 0);

            var builder = new Notification.Action.Builder(Android.Resource.Drawable.IcMediaPause,
                                                          "Stop Timer",
                                                          stopServicePendingIntent);

            StopForeground(true);

            return(builder.Build());
        }
예제 #12
0
        public static void SendDumbNotification()
        {
            NotificationManager notificationManager = (NotificationManager)Application.Context.GetSystemService("notification");

            Notification.Builder builder;
            if (Build.VERSION.SdkInt < BuildVersionCodes.NMr1)
            {
#pragma warning disable CS0618 // 'Notification.Builder.SetPriority(int)' está obsoleto: 'deprecated'

                builder = new Notification.Builder(Application.Context);
                builder.SetPriority(Convert.ToInt32(NotificationPriority.Max));
#pragma warning restore CS0618 // 'Notification.Builder.SetPriority(int)' está obsoleto: 'deprecated'
            }
            else
            {
                NotificationChannel notificationChannel = new NotificationChannel("livedisplaynotificationchannel", "LiveDisplay", NotificationImportance.Max);
                notificationManager.CreateNotificationChannel(notificationChannel);
                builder = new Notification.Builder(Application.Context, "livedisplaynotificationchannel");
            }

            RemoteInput remoteInput = new RemoteInput.Builder("test1").SetLabel("This is the place where you write").Build();

            Intent intent = new Intent(Application.Context, Java.Lang.Class.FromType(typeof(MainActivity)));

            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 35, intent, PendingIntentFlags.UpdateCurrent);

            Notification.Action.Builder action = new Notification.Action.Builder(Resource.Drawable.ic_stat_default_appicon, "Answer", pendingIntent).AddRemoteInput(remoteInput);

            builder.SetStyle(new Notification.MessagingStyle("Su madre").AddMessage(new Notification.MessagingStyle.Message("hi", -1, "user1"))
                             .AddMessage(new Notification.MessagingStyle.Message("WhatsUp", 0, "user2"))
                             .AddMessage(new Notification.MessagingStyle.Message("How bout lunch?", 1, "user1")));
#pragma warning restore
            builder.SetContentTitle("");
            builder.SetContentText("");
            builder.SetAutoCancel(true);
            builder.AddAction(action.Build());

            builder.SetSmallIcon(Resource.Drawable.ic_stat_default_appicon);
            notificationManager.Notify(2, builder.Build());
        }
예제 #13
0
        public void PostNotification(int notifid, string title, string text, bool autoCancellable, NotificationImportance notificationImportance)
        {
            NotificationChannel notificationChannel = new NotificationChannel("livedisplaynotificationchannel", "LiveDisplay", notificationImportance);

            notificationManager.CreateNotificationChannel(notificationChannel);
            Notification.Builder builder = new Notification.Builder(Application.Context, "livedisplaynotificationchannel");
            builder.SetContentTitle(title);
            builder.SetContentText(text);
            builder.SetAutoCancel(autoCancellable);
            builder.SetSmallIcon(Resource.Drawable.ic_stat_default_appicon);
            builder.SetAutoCancel(true);

            RemoteInput remoteInput = new RemoteInput.Builder("test1").SetLabel("This is the place where you write").Build();

            Intent intent = new Intent(Application.Context, Java.Lang.Class.FromType(typeof(SettingsActivity)));

            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 35, intent, PendingIntentFlags.UpdateCurrent);

            Notification.Action.Builder action = new Notification.Action.Builder(Resource.Drawable.ic_stat_default_appicon, "Answer", pendingIntent).AddRemoteInput(remoteInput);

            builder.AddAction(action.Build());

            notificationManager.Notify(notifid, builder.Build());
        }
예제 #14
0
		/// <summary>
		/// Builds a Notification.Action that will instruct the service to restart the timer.
		/// </summary>
		/// <returns>The restart timer action.</returns>
		Notification.Action BuildRestartTimerAction()
		{
			var restartTimerIntent = new Intent(this, GetType());
			restartTimerIntent.SetAction(Constants.ACTION_RESTART_TIMER);
			var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartTimerIntent, 0);

			var builder = new Notification.Action.Builder(Resource.Drawable.ic_action_restart_timer,
											  GetText(Resource.String.restart_timer),
											  restartTimerPendingIntent);

			return builder.Build();
		}
		public override void OnDataChanged (DataEventBuffer eventBuffer)
		{
			var events = FreezableUtils.FreezeIterable (eventBuffer);
			eventBuffer.Close ();

			var google_api_client = new GoogleApiClientBuilder (this)
				.AddApi (WearableClass.API)
				.Build ();

			var connectionResult = google_api_client.BlockingConnect (Constants.CONNECT_TIMEOUT_MS,
				                       TimeUnit.Milliseconds);

			if (!connectionResult.IsSuccess) {
				Log.Error (TAG, "QuizListenerService failed to connect to GoogleApiClient.");
				return;
			}

			foreach (var ev in events) {
				var e = ((Java.Lang.Object)ev).JavaCast<IDataEvent> ();
				if (e.Type == DataEvent.TypeChanged) {
					var dataItem = e.DataItem;
					var dataMap = DataMapItem.FromDataItem (dataItem).DataMap;
					if (dataMap.GetBoolean (Constants.QUESTION_WAS_ANSWERED)
					    || dataMap.GetBoolean (Constants.QUESTION_WAS_DELETED)) {
						continue;
					}

					string question = dataMap.GetString (Constants.QUESTION);
					int questionIndex = dataMap.GetInt (Constants.QUESTION_INDEX);
					int questionNum = questionIndex + 1;
					string[] answers = dataMap.GetStringArray (Constants.ANSWERS);
					int correctAnswerIndex = dataMap.GetInt (Constants.CORRECT_ANSWER_INDEX);
					Intent deleteOperation = new Intent (this, typeof(DeleteQuestionService));
					deleteOperation.SetData (dataItem.Uri);
					PendingIntent deleteIntent = PendingIntent.GetService (this, 0,
						                             deleteOperation, PendingIntentFlags.UpdateCurrent);
					//first page of notification contains question as Big Text.
					var bigTextStyle = new Notification.BigTextStyle ()
						.SetBigContentTitle (GetString (Resource.String.question, questionNum))
						.BigText (question);
					var builder = new Notification.Builder (this)
						.SetStyle (bigTextStyle)
						.SetSmallIcon (Resource.Drawable.ic_launcher)
						.SetLocalOnly (true)
						.SetDeleteIntent (deleteIntent);

					//add answers as actions
					var wearableOptions = new Notification.WearableExtender ();
					for (int i = 0; i < answers.Length; i++) {
						Notification answerPage = new Notification.Builder (this)
							.SetContentTitle (question)
							.SetContentText (answers [i])
							.Extend (new Notification.WearableExtender ()
								.SetContentAction (i))
							.Build ();

						bool correct = (i == correctAnswerIndex);
						var updateOperation = new Intent (this, typeof(UpdateQuestionService));
						//Give each intent a unique action.
						updateOperation.SetAction ("question_" + questionIndex + "_answer_" + i);
						updateOperation.SetData (dataItem.Uri);
						updateOperation.PutExtra (UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex);
						updateOperation.PutExtra (UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct);
						var updateIntent = PendingIntent.GetService (this, 0, updateOperation,
							                   PendingIntentFlags.UpdateCurrent);
						Notification.Action action = new Notification.Action.Builder (
							                             (int)question_num_to_drawable_id.Get (i), (string)null, updateIntent)
							.Build ();
						wearableOptions.AddAction (action).AddPage (answerPage);
					}
					builder.Extend (wearableOptions);
					Notification notification = builder.Build ();
					((NotificationManager)GetSystemService (NotificationService))
						.Notify (questionIndex, notification);
				} else if (e.Type == DataEvent.TypeDeleted) {
					Android.Net.Uri uri = e.DataItem.Uri;
					//URIs are in the form of "/question/0", "/question/1" etc.
					//We use the question index as the notification id.
					int notificationId = Java.Lang.Integer.ParseInt (uri.LastPathSegment);
					((NotificationManager)GetSystemService (NotificationService))
						.Cancel (notificationId);
				}

				((NotificationManager)GetSystemService (NotificationService))
					.Cancel (QUIZ_REPORT_NOTIF_ID);
			}
			google_api_client.Disconnect ();
		}
예제 #16
0
파일: AndroidWearImpl.cs 프로젝트: P0W/AR
        public void ProcessRxData(int airdropPhase)
        {
            int _ap = airdropPhase;

            if (_ap == 3)
            {
                ARModel.GetInstance.AirdropPhase = 3;
                var valuesForActivity = new Bundle();
                valuesForActivity.Equals("message");
                string groupkey = "group_key";
                var    intent   = new Intent(currentActivity, typeof(MainActivity));
                intent.PutExtras(valuesForActivity);
                var pendingIntent = PendingIntent.GetActivity(currentActivity, 0, intent, PendingIntentFlags.OneShot);
                var builder       = new Notification.Builder(currentActivity)
                                    .SetAutoCancel(true)
                                    .SetContentIntent(pendingIntent)
                                    .SetContentTitle("Welcome to CHADCS")
                                                                              //.SetSmallIcon(Resource.Drawable.greeen)
                                                                              //.SetLargeIcon(Resource.Drawable.red)
                                    .SetContentText("AirDrop Light is Green") //message is the one recieved from the notification
                                    .SetGroup(groupkey)                       //creates groups
                                    .SetShowWhen(true)
                                    .SetLocalOnly(false)
                                    .SetVisibility(NotificationVisibility.Public)
                                    .SetPriority((int)NotificationPriority.High);
                //                .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);

                //intent for voice input or text selection
                var wear_intent         = new Intent(Intent.ActionView);
                var wear_pending_intent = PendingIntent.GetActivity(currentActivity, 0, wear_intent, 0);



                // Create the reply action and add the remote input
                var action = new Notification.Action.Builder(Resource.Drawable.icon, "Ok Light", wear_pending_intent)
                             .Build();

                //add it to the notification builder
                Notification notification = builder.Extend(new Notification.WearableExtender()).Build();

                int notification_id = 1;
                if (notification_id < 9)
                {
                    notification_id += 1;
                }
                else
                {
                    notification_id = 0;
                }

                //var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                notifyManager.Notify(notification_id + 2, notification);
            }
            else if (_ap == 2)
            {
                //ARModel.GetInstance.AirdropPhase = 3;
                var valuesForActivity = new Bundle();
                valuesForActivity.Equals("message");
                string groupkey = "group_key";
                var    intent   = new Intent(currentActivity, typeof(MainActivity));
                intent.PutExtras(valuesForActivity);
                var pendingIntent = PendingIntent.GetActivity(currentActivity, 0, intent, PendingIntentFlags.OneShot);
                var builder       = new Notification.Builder(currentActivity)
                                    .SetAutoCancel(true)
                                    .SetContentIntent(pendingIntent)
                                    .SetContentTitle("Welcome to CHADCS")
                                                                               //.SetSmallIcon(Resource.Drawable.yellow)
                                                                               //.SetLargeIcon(Resource.Drawable.red)
                                    .SetContentText("AirDrop Light is Yellow") //message is the one recieved from the notification
                                    .SetGroup(groupkey)                        //creates groups
                                    .SetShowWhen(true)
                                    .SetLocalOnly(false)
                                    .SetVisibility(NotificationVisibility.Public)
                                    .SetPriority((int)NotificationPriority.High);
                //                .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);

                //intent for voice input or text selection
                var wear_intent         = new Intent(Intent.ActionView);
                var wear_pending_intent = PendingIntent.GetActivity(currentActivity, 0, wear_intent, 0);



                // Create the reply action and add the remote input
                var action = new Notification.Action.Builder(Resource.Drawable.icon, "Ok Light", wear_pending_intent)
                             .Build();

                //add it to the notification builder
                Notification notification = builder.Extend(new Notification.WearableExtender()).Build();

                int notification_id = 1;
                if (notification_id < 9)
                {
                    notification_id += 1;
                }
                else
                {
                    notification_id = 0;
                }

                //var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                notifyManager.Notify(notification_id + 2, notification);
            }

            else if (_ap == 1)
            {
                //ARModel.GetInstance.AirdropPhase = 3;
                var valuesForActivity = new Bundle();
                valuesForActivity.Equals("message");
                string groupkey = "group_key";
                var    intent   = new Intent(currentActivity, typeof(MainActivity));
                intent.PutExtras(valuesForActivity);
                var pendingIntent = PendingIntent.GetActivity(currentActivity, 0, intent, PendingIntentFlags.OneShot);
                var builder       = new Notification.Builder(currentActivity)
                                    .SetAutoCancel(true)
                                    .SetContentIntent(pendingIntent)
                                    .SetContentTitle("Welcome to CHADCS")
                                                                            //.SetSmallIcon(Resource.Drawable.red)
                                                                            //.SetLargeIcon(Resource.Drawable.red)
                                    .SetContentText("AirDrop Light is Red") //message is the one recieved from the notification
                                    .SetGroup(groupkey)                     //creates groups
                                    .SetShowWhen(true)
                                    .SetLocalOnly(false)
                                    .SetVisibility(NotificationVisibility.Public)
                                    .SetPriority((int)NotificationPriority.High);
                //                .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);

                //intent for voice input or text selection
                var wear_intent         = new Intent(Intent.ActionView);
                var wear_pending_intent = PendingIntent.GetActivity(currentActivity, 0, wear_intent, 0);



                // Create the reply action and add the remote input
                var action = new Notification.Action.Builder(Resource.Drawable.icon, "Ok Light", wear_pending_intent)
                             .Build();

                //add it to the notification builder
                Notification notification = builder.Extend(new Notification.WearableExtender()).Build();

                int notification_id = 1;
                if (notification_id < 9)
                {
                    notification_id += 1;
                }
                else
                {
                    notification_id = 0;
                }

                //var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                notifyManager.Notify(notification_id + 2, notification);
            }
        }
예제 #17
0
        public override void OnDataChanged(DataEventBuffer eventBuffer)
        {
            var events = FreezableUtils.FreezeIterable(eventBuffer);

            eventBuffer.Close();

            var google_api_client = new GoogleApiClientBuilder(this)
                                    .AddApi(WearableClass.API)
                                    .Build();

            var connectionResult = google_api_client.BlockingConnect(Constants.CONNECT_TIMEOUT_MS,
                                                                     TimeUnit.Milliseconds);

            if (!connectionResult.IsSuccess)
            {
                Log.Error(TAG, "QuizListenerService failed to connect to GoogleApiClient.");
                return;
            }

            foreach (var ev in events)
            {
                var e = ((Java.Lang.Object)ev).JavaCast <IDataEvent> ();
                if (e.Type == DataEvent.TypeChanged)
                {
                    var dataItem = e.DataItem;
                    var dataMap  = DataMapItem.FromDataItem(dataItem).DataMap;
                    if (dataMap.GetBoolean(Constants.QUESTION_WAS_ANSWERED) ||
                        dataMap.GetBoolean(Constants.QUESTION_WAS_DELETED))
                    {
                        continue;
                    }

                    string   question           = dataMap.GetString(Constants.QUESTION);
                    int      questionIndex      = dataMap.GetInt(Constants.QUESTION_INDEX);
                    int      questionNum        = questionIndex + 1;
                    string[] answers            = dataMap.GetStringArray(Constants.ANSWERS);
                    int      correctAnswerIndex = dataMap.GetInt(Constants.CORRECT_ANSWER_INDEX);
                    Intent   deleteOperation    = new Intent(this, typeof(DeleteQuestionService));
                    deleteOperation.SetData(dataItem.Uri);
                    PendingIntent deleteIntent = PendingIntent.GetService(this, 0,
                                                                          deleteOperation, PendingIntentFlags.UpdateCurrent);
                    //first page of notification contains question as Big Text.
                    var bigTextStyle = new Notification.BigTextStyle()
                                       .SetBigContentTitle(GetString(Resource.String.question, questionNum))
                                       .BigText(question);
                    var builder = new Notification.Builder(this)
                                  .SetStyle(bigTextStyle)
                                  .SetSmallIcon(Resource.Drawable.ic_launcher)
                                  .SetLocalOnly(true)
                                  .SetDeleteIntent(deleteIntent);

                    //add answers as actions
                    var wearableOptions = new Notification.WearableExtender();
                    for (int i = 0; i < answers.Length; i++)
                    {
                        Notification answerPage = new Notification.Builder(this)
                                                  .SetContentTitle(question)
                                                  .SetContentText(answers [i])
                                                  .Extend(new Notification.WearableExtender()
                                                          .SetContentAction(i))
                                                  .Build();

                        bool correct         = (i == correctAnswerIndex);
                        var  updateOperation = new Intent(this, typeof(UpdateQuestionService));
                        //Give each intent a unique action.
                        updateOperation.SetAction("question_" + questionIndex + "_answer_" + i);
                        updateOperation.SetData(dataItem.Uri);
                        updateOperation.PutExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex);
                        updateOperation.PutExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct);
                        var updateIntent = PendingIntent.GetService(this, 0, updateOperation,
                                                                    PendingIntentFlags.UpdateCurrent);
                        Notification.Action action = new Notification.Action.Builder(
                            (int)question_num_to_drawable_id.Get(i), (string)null, updateIntent)
                                                     .Build();
                        wearableOptions.AddAction(action).AddPage(answerPage);
                    }
                    builder.Extend(wearableOptions);
                    Notification notification = builder.Build();
                    ((NotificationManager)GetSystemService(NotificationService))
                    .Notify(questionIndex, notification);
                }
                else if (e.Type == DataEvent.TypeDeleted)
                {
                    Android.Net.Uri uri = e.DataItem.Uri;
                    //URIs are in the form of "/question/0", "/question/1" etc.
                    //We use the question index as the notification id.
                    int notificationId = Java.Lang.Integer.ParseInt(uri.LastPathSegment);
                    ((NotificationManager)GetSystemService(NotificationService))
                    .Cancel(notificationId);
                }

                ((NotificationManager)GetSystemService(NotificationService))
                .Cancel(QUIZ_REPORT_NOTIF_ID);
            }
            google_api_client.Disconnect();
        }
예제 #18
0
		/// <summary>
		/// Builds the Notification.Action that will allow the user to stop the service via the
		/// notification in the status bar
		/// </summary>
		/// <returns>The stop service action.</returns>
		Notification.Action BuildStopServiceAction()
		{
			var stopServiceIntent = new Intent(this, GetType());
			stopServiceIntent.SetAction(Constants.ACTION_STOP_SERVICE);
			var stopServicePendingIntent = PendingIntent.GetService(this, 0, stopServiceIntent, 0);

			var builder = new Notification.Action.Builder(Android.Resource.Drawable.IcMediaPause,
														  GetText(Resource.String.stop_service),
														  stopServicePendingIntent);
			return builder.Build();

		}