예제 #1
0
		private void CreateNotification(Intent intent) {
			recipe = Recipe.FromBundle(intent.GetBundleExtra(Constants.ExtraRecipe));
			List<Notification> notificationPages = new List<Notification> ();

			int stepCount = recipe.RecipeSteps.Count;

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

			var notifBuilder = new NotificationCompat.Builder(this);

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

			Notification notification = notifBuilder.Extend(new NotificationCompat.WearableExtender().AddPages(notificationPages)).Build();
			notificationManager.Notify (Constants.NotificationId, notification);
		}
        public override void OnReceive(Context context, Intent intent)
        {
            if (RetreiveLatestReceiver.IsAvailableVersion(context))
            {
                intent.PutExtra("title", string.Format(context.Resources.GetString(Resource.String.notification_title), "WhatsApp " + RetreiveLatestReceiver.GetLatestVersion()));
                intent.PutExtra("message", string.Format(context.Resources.GetString(Resource.String.notification_description), context.Resources.GetString(Resource.String.app_name)));
                var message = intent.GetStringExtra("message");
                var title   = intent.GetStringExtra("title");

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

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

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

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

                var notification = builder.Build();
                manager.Notify(0, notification);
            }
        }
        private void ShowNotification()
        {
            if (Log.IsLoggable(TAG, LogPriority.Debug))
            {
                Log.Debug(TAG, "Sent: " + mLastResponse);
            }

            var builder = new NotificationCompat.Builder(this)
                          .SetContentTitle(GetString(Resource.String.eliza))
                          .SetContentText(mLastResponse)
                          .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.bg_eliza))
                          .SetSmallIcon(Resource.Drawable.bg_eliza)
                          .SetPriority(NotificationCompat.PriorityMin);

            var intent        = new Intent(ACTION_RESPONSE);
            var pendingIntent = PendingIntent.GetService(this, 0, intent, PendingIntentFlags.OneShot | PendingIntentFlags.CancelCurrent);
            var notification  = builder
                                .Extend(new NotificationCompat.WearableExtender()
                                        .AddAction(new NotificationCompat.Action.Builder
                                                       (Resource.Drawable.ic_full_reply, GetString(Resource.String.reply), pendingIntent)
                                                   .AddRemoteInput(new RemoteInput.Builder(EXTRA_REPLY).SetLabel(GetString(Resource.String.reply)).Build())
                                                   .Build()))
                                .Build();

            NotificationManagerCompat.From(this).Notify(NOTIFICATION_ID, notification);
        }
		public override void OnReceive (Context context, Intent intent) {
			if (RetreiveLatestReceiver.IsAvailableVersion(context)) {
				intent.PutExtra ("title", string.Format(context.Resources.GetString(Resource.String.notification_title), "WhatsApp " + RetreiveLatestReceiver.GetLatestVersion ()));
				intent.PutExtra ("message", string.Format(context.Resources.GetString(Resource.String.notification_description), context.Resources.GetString(Resource.String.app_name)));
				var message = intent.GetStringExtra ("message");
				var title = intent.GetStringExtra ("title");

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

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

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

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

				var notification = builder.Build ();
				manager.Notify (0, notification);
			}
		}
        private void CreateNotification(Intent intent)
        {
            recipe = Recipe.FromBundle(intent.GetBundleExtra(Constants.ExtraRecipe));
            List <Notification> notificationPages = new List <Notification> ();

            int stepCount = recipe.RecipeSteps.Count;

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

            var notifBuilder = new NotificationCompat.Builder(this);

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

            Notification notification = notifBuilder.Extend(new NotificationCompat.WearableExtender().AddPages(notificationPages)).Build();

            notificationManager.Notify(Constants.NotificationId, notification);
        }
예제 #6
0
        private void btnSendNotificationWithMultiplePages_OnClick(object sender, EventArgs eventArgs)
        {
            // Specify the 'big view' content to display the long
            var bigStyle = new NotificationCompat.BigTextStyle();

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

            var builder = new NotificationCompat.Builder(Context);

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

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

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


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

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


            NotificationManagerCompat.From(Context).Notify(119, notification);
        }
예제 #7
0
        private void ShowNotification(string cityId, bool microApp)
        {
            var attractions = TouristAttractionsHelper.Attractions[cityId];

            if (microApp)
            {
                //TODO:
                // If micro app we first need to transfer some data over
                //sendDataToWearable(attractions);
            }

            // The first (closest) tourist attraction
            Attraction attraction = attractions[0];

            // Limit attractions to send
            int count = (attractions.Count) > Constants.MAX_ATTRACTIONS ?
                        Constants.MAX_ATTRACTIONS : attractions.Count;

            // Pull down the tourist attraction images from the network and store
            var bitmaps = new Dictionary <string, Bitmap>();

            try
            {
                for (int i = 0; i < count; i++)
                {
                    //TODO:
                    //bitmaps.Put(attractions[i].Name,
                    //		Glide.with(this)
                    //				.load(attractions.get(i).imageUrl)
                    //				.asBitmap()
                    //				.diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    //				.into(Constants.WEAR_IMAGE_SIZE, Constants.WEAR_IMAGE_SIZE)
                    //				.get());

                    var bm = Koush.UrlImageViewHelper.GetCachedBitmap(attractions[i].ImageUrl.AbsoluteUri);
                    bitmaps.Add(attractions[i].Name, bm);
                }
            }
            catch (Exception e)
            {
                Log.Error("UtilityService", "Error fetching image from network: " + e);
            }

            // The intent to trigger when the notification is tapped
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0,
                                                                    DetailActivity.GetLaunchIntent(this, attraction.Name),
                                                                    PendingIntentFlags.UpdateCurrent);

            // The intent to trigger when the notification is dismissed, in this case
            // we want to clear remote notifications as well
            PendingIntent deletePendingIntent =
                PendingIntent.GetService(this, 0, GetClearRemoteNotificationsIntent(this), 0);

            // Construct the main notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetStyle(new NotificationCompat.BigPictureStyle()
                                                           .BigPicture(bitmaps[attraction.Name])
                                                           .SetBigContentTitle(attraction.Name)
                                                           .SetSummaryText(GetString(Resource.String.nearby_attraction))
                                                           )
                                                 .SetLocalOnly(microApp)
                                                 .SetContentTitle(attraction.Name)
                                                 .SetContentText(GetString(Resource.String.nearby_attraction))
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_maps_pin_drop)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetDeleteIntent(deletePendingIntent)
                                                 .SetColor(Resources.GetColor(Resource.Color.colorPrimary, Theme))
                                                 .SetCategory(Notification.CategoryRecommendation)
                                                 .SetAutoCancel(true);

            if (!microApp)
            {
                // If not a micro app, create some wearable pages for
                // the other nearby tourist attractions.
                List <Notification> pages = new List <Notification>();
                for (int i = 1; i < count; i++)
                {
                    // Calculate the distance from current location to tourist attraction
                    String distance = Utils.FormatDistanceBetween(
                        Utils.GetLocation(this), attractions[i].Location);

                    // Construct the notification and add it as a page
                    pages.Add(new NotificationCompat.Builder(this)
                              .SetContentTitle(attractions[i].Name)
                              .SetContentText(distance)
                              .SetSmallIcon(Resource.Drawable.ic_stat_maps_pin_drop)
                              .Extend(new NotificationCompat.WearableExtender()
                                      .SetBackground(bitmaps[attractions[i].Name])
                                      )
                              .Build());
                }
                builder.Extend(new NotificationCompat.WearableExtender().AddPages(pages));
            }

            // Trigger the notification
            NotificationManagerCompat.From(this).Notify(
                Constants.MOBILE_NOTIFICATION_ID, builder.Build());
        }
		private void ShowNotification ()
		{
			if (Log.IsLoggable (TAG, LogPriority.Debug))
				Log.Debug (TAG, "Sent: " + mLastResponse);

			var builder = new NotificationCompat.Builder (this)
				.SetContentTitle (GetString (Resource.String.eliza))
				.SetContentText (mLastResponse)
				.SetLargeIcon (BitmapFactory.DecodeResource (Resources, Resource.Drawable.bg_eliza))
				.SetSmallIcon (Resource.Drawable.bg_eliza)
				.SetPriority (NotificationCompat.PriorityMin);

			var intent = new Intent (ACTION_RESPONSE);
			var pendingIntent = PendingIntent.GetService (this, 0, intent, PendingIntentFlags.OneShot | PendingIntentFlags.CancelCurrent);
			var notification = builder
				.Extend (new NotificationCompat.WearableExtender ()
					.AddAction (new NotificationCompat.Action.Builder 
						(Resource.Drawable.ic_full_reply, GetString (Resource.String.reply), pendingIntent)
						.AddRemoteInput (new RemoteInput.Builder (EXTRA_REPLY).SetLabel (GetString (Resource.String.reply)).Build ())
						.Build ()))
				.Build ();
			NotificationManagerCompat.From (this).Notify (NOTIFICATION_ID, notification);
		}