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); } }
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); } }
//push notification for phone and android wear private void PushNotification(Intent intent) { var style = new NotificationCompat.BigTextStyle().BigText(durationString); //wearable notification var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.trucktrackbackground)); try { // Instantiate the builder and set notification elements: builder.SetContentTitle(suggestString) .SetContentText(durationString) .SetSmallIcon(Resource.Drawable.trucktrackicon) .SetStyle(style) //2 for max priority .SetPriority(2) //2 for vibration .SetDefaults(2) //0x1 for sound .SetDefaults(0x1) //enable wearable extender .Extend(wearableExtender); // Build the notification: notification = builder.Build(); // Publish the notification: const int notificationId = 0; notificationManager.Notify(notificationId, notification); }catch { } }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainScreen)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId = Resource.Drawable.HappyBaby; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.HappyBaby) .SetSound(Android.Net.Uri.Parse("android.resource://com.iinotification.app/" + Resource.Raw.babySound)) .SetContentTitle("Hey Mom") .SetContentText("Here I'm :)") .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
public override void OnReceive(Context context, Intent intent) { var id = intent.GetStringExtra("id"); var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); notIntent.PutExtra("id", id); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); int resourceId = Resource.Drawable.ic_launcher_xx; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_launcher_xx) .SetContentTitle(title) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(int.Parse(id), notification); }
public override bool OnStartJob(JobParameters @params) { Log.Error("lv", "222222222222222"); Intent notIntent = new Intent(this, typeof(MainActivity)); PendingIntent contentIntent = PendingIntent.GetActivity(this, 0, notIntent, PendingIntentFlags.UpdateCurrent); NotificationManagerCompat manager = NotificationManagerCompat.From(this); var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.pause)); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.play) .SetContentTitle("title") .SetContentText("message") .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .Extend(wearableExtender); Notification notification = builder.Build(); notification.Flags = NotificationFlags.AutoCancel; manager.Notify(0, notification); JobFinished(@params, false); return(true); }
public override void OnReceive (Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainScreen)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId = Resource.Drawable.HappyBaby; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.HappyBaby) .SetSound(Android.Net.Uri.Parse("android.resource://com.iinotification.app/"+ Resource.Raw.babySound)) .SetContentTitle("Hey Mom") .SetContentText("Here I'm :)") .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity1)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.UpdateCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId; resourceId = Resource.Drawable.ic_stat_button_click; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)) ; var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_button_click) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); // seto o icone da notificação int resourceId = Resource.Drawable.abc_btn_check_material; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)) ; //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.abc_btn_check_material) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); // sets notifcation logo int resourceId; resourceId = Resource.Drawable.xamarin_logo; var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); // Generate a notification // todo look at notification compat properties var builder = new NotificationCompat.Builder(context, channelId) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.notification_template_icon_bg) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); // this seems to work when the above notify doesnt work // var resultIntent = NotificationService.GetLauncherActivity(); //resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); //var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context); //stackBuilder.AddNextIntent(resultIntent); //Random random = new Random(); //int randomNumber = random.Next(9999 - 1000) + 1000; //var resultPendingIntent = // stackBuilder.GetPendingIntent(randomNumber, (int)PendingIntentFlags.Immutable); //builder.SetContentIntent(resultPendingIntent); //// Sending notification //var notificationManager = NotificationManagerCompat.From(Application.Context); //notificationManager.Notify(randomNumber, builder.Build()); }
private void PopUpNotification(int id, string title, string message) { var wearableExtender = new NotificationCompat.WearableExtender() .SetHintHideIcon(true); Bitmap bitmap = null; try{ bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.wear_background); }catch (Exception ex) { } if (bitmap != null) { wearableExtender.SetBackground(bitmap); } var builder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_notification) .SetContentTitle(title) .SetContentText(message) .Extend(wearableExtender) .SetAutoCancel(true); // Creates an explicit intent for an Activity in your app var 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. var stackBuilder = Android.Support.V4.App.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); var resultPendingIntent = stackBuilder.GetPendingIntent( 0, (int)PendingIntentFlags.UpdateCurrent ); builder.SetContentIntent(resultPendingIntent); var notificationManager = NotificationManagerCompat.From(this); // mId allows you to update the notification later on. notificationManager.Notify(id, builder.Build()); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId; if (App.SelectedModel.VehicleType == "Car") { resourceId = Resource.Drawable.Car; } else if (App.SelectedModel.VehicleType == "Bike") { resourceId = Resource.Drawable.Bike; } else { resourceId = Resource.Drawable.Other; } var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)) ; //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); Button button = FindViewById <Button>(Resource.Id.MyButton); button.Click += delegate { // Wear の入力画面を構築 // RemoteInput.Builder だと Android.RemoteInput と競合するのでフルで指定しています。 // 正式な書き方は不明です。。 var remoteInput = new Android.Support.V4.App.RemoteInput.Builder("Reply") .SetLabel(GetText(Resource.String.Reply)) // "Reply Label" .Build(); // pendingIntent で起動する Activity var intent = new Intent(this, typeof(StartActionActivity)); // Wear の Update を待つ処理 var replyPendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); // Wear でスワイプ (Extender?) した際のアクション var replyAction = new NotificationCompat.Action.Builder( Android.Resource.Drawable.IcButtonSpeakNow, GetText(Resource.String.Reply), replyPendingIntent) // "リプライ" .AddRemoteInput(remoteInput) .Build(); // Wear の Extender を構築 var wealableExtender = new NotificationCompat.WearableExtender() .AddAction(replyAction); // Wear の Notification を構築 var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Android.Resource.Drawable.IcDialogAlert) .SetContentTitle(GetText(Resource.String.AlertTitle)) // "アラート" .SetContentText(GetText(Resource.String.AlertMessage)) // "左にスワイプしてください" .Extend(wealableExtender); // Notification を送る Activity を指定 var notificationManager = NotificationManagerCompat.From(this); // 実際に Notification を送る notificationManager.Notify(1, notificationBuilder.Build()); }; }
public override void OnReceive (Context context, Intent intent) { var message = intent.GetStringExtra ("message"); var title = intent.GetStringExtra ("title"); var notIntent = new Intent (context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity (context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From (context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId; if (App.SelectedModel.VehicleType == "Car") resourceId = Resource.Drawable.Car; else if (App.SelectedModel.VehicleType == "Bike") resourceId = Resource.Drawable.Bike; else resourceId = Resource.Drawable.Other; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)) ; //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder (context) .SetContentIntent (contentIntent) .SetSmallIcon (Resource.Drawable.ic_launcher) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); var button = FindViewById <Button> (Resource.Id.myButton); button.Click += delegate { var pendingIntent = PendingIntent.GetActivity(this, 100, new Intent(this, typeof(MainActivity)), PendingIntentFlags.UpdateCurrent); var largeIcon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.monkey); var builder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_logo) .SetLargeIcon(largeIcon) .SetContentText("Short Service announcement") .SetContentTitle("Page 1") .SetContentIntent(pendingIntent); var secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.BigText("Xamarin.Android goes on your Android Wear too"); var secondNotification = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_logo) .SetLargeIcon(largeIcon) .SetContentTitle("Page 2") .SetStyle(secondPageStyle) .Build(); var twoPageNotification = new NotificationCompat.WearableExtender() .AddPage(secondNotification) .Extend(builder) .Build(); NotificationManagerCompat.From(this).Notify("multi-page-notification", 1000, twoPageNotification); }; }
public override void OnReceive(Context context, Intent intent) { Toast.MakeText(context, "Received intent!", ToastLength.Short).Show(); Intent notIntent = new Intent(context, typeof(MainActivity)); PendingIntent contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); NotificationManagerCompat manager = NotificationManagerCompat.From(context); var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pause)); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.play).SetContentTitle("title") .SetContentText("message") .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .Extend(wearableExtender); Notification notification = builder.Build(); notification.Flags = NotificationFlags.AutoCancel; manager.Notify(0, notification); }
private void ShowNotification(Intent intent) { const string key = "msg"; if (!intent.Extras.ContainsKey(key)) { return; } var message = intent.Extras.GetString(key); NotificationMessage notification; try { notification = JsonConvert.DeserializeObject <NotificationMessage>(message); } catch (Exception ex) { App.Logger.Report(ex); return; } if (notification == null || string.IsNullOrWhiteSpace(notification.Message)) { return; } var notificationManager = NotificationManagerCompat.From(this); Intent notificationIntent = null; int id = notification.FromId; //if user id came in then let's send them to that page. if (id <= 0) { id = Settings.GetNotificationId(); notificationIntent = new Intent(this, typeof(WelcomeActivity)); } else { notificationIntent = new Intent(this, typeof(ConversationActivity)); notificationIntent.PutExtra(ConversationActivity.RecipientId, (long)id); } notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask); var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent); var wearableExtender = new NotificationCompat.WearableExtender() .SetContentIcon(Resource.Drawable.ic_launcher); var builder = new NotificationCompat.Builder(this) .SetContentIntent(pendingIntent) .SetContentTitle("Kinder Chat") .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.ic_notification) .SetContentText(notification.Message) .Extend(wearableExtender); // Obtain a reference to the NotificationManager var notif = builder.Build(); notif.Defaults = NotificationDefaults.All; //add sound, vibration, led :) notificationManager.Notify(id, notif); }
// from https://xamarinhelp.com/xamarin-background-tasks/ public override async void OnReceive(Context context, Intent intent) { //PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService); //PowerManager.WakeLock wakeLock = pm.NewWakeLock(WakeLockFlags.Partial, "BackgroundReceiver"); ////wakeLock.Acquire(); //var alarmIntent = new Intent(context, typeof(BackgroundReceiver)); //var pending = PendingIntent.GetBroadcast(context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent); //var alarmManager = (AlarmManager)Android.App.Application.Context.GetSystemService(Context.AlarmService); //alarmManager.SetExactAndAllowWhileIdle(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 1 * 1000, pending); ////MessagingCenter.Send<object, string>(this, "UpdateLabel", "Hello from Android"); //MessagingCenter.Send<object>(this, "SendNotification"); ///// //Intent alarmIntent = new Intent(Application.Context, typeof(AlarmReceiver)); //alarmIntent.PutExtra("message", message); //alarmIntent.PutExtra("title", title); //// specify the broadcast receiver //PendingIntent pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent); //AlarmManager alarmManager = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService); //// set the time when app is woken up //// todo: this is where time is adjusted //alarmManager.SetInexactRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 5 * 1000, 1000, pendingIntent); _sqLiteConnection = await Xamarin.Forms.DependencyService.Get <ISQLite>().GetConnection(); var listDataPower = _sqLiteConnection.Table <Power>().ToList(); iteratedIndex++; //title = listDataPower[iteratedIndex].Title; //message = listDataPower[iteratedIndex].Description; var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); // sets notifcation logo int resourceId; resourceId = Resource.Drawable.xamarin_logo; var wearableExtender = new NotificationCompat.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); // Generate a notification // todo look at notification compat properties var builder = new NotificationCompat.Builder(context, channelId) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.notification_template_icon_bg) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var resultIntent = NotificationService.GetLauncherActivity(); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context); stackBuilder.AddNextIntent(resultIntent); Random random = new Random(); int randomNumber = random.Next(9999 - 1000) + 1000; var resultPendingIntent = stackBuilder.GetPendingIntent(randomNumber, (int)PendingIntentFlags.Immutable); builder.SetContentIntent(resultPendingIntent); // Sending notification var notificationManager = NotificationManagerCompat.From(Application.Context); notificationManager.Notify(randomNumber, builder.Build()); //var notification = builder.Build(); //manager.Notify(0, notification); ///////////////////////////////////////////////////////// /// //wakeLock.Release(); ////////////////////////////////////////////////////////////////////// }
private async void ShowNotification(Intent intent) { const string msgKey = "msg"; const string senderIdKey = "senderid"; const string senderKey = "sender"; const string iconKey = "icon"; if (!intent.Extras.ContainsKey(msgKey) || !intent.Extras.ContainsKey(senderIdKey) || !intent.Extras.ContainsKey(senderKey) || !intent.Extras.ContainsKey(iconKey)) { return; } NotificationMessage notification = new NotificationMessage(); notification.Title = intent.Extras.GetString(senderKey); notification.Message = intent.Extras.GetString(msgKey); notification.IconUrl = intent.Extras.GetString(iconKey); notification.FromId = int.Parse(intent.Extras.GetString(senderIdKey)); Bitmap largeIconBitmap = await GetImageBitmapFromUrlAsync(EndPoints.BaseUrl + notification.IconUrl); var notificationManager = NotificationManagerCompat.From(this); Intent notificationIntent = null; int id = notification.FromId; //if user id came in then let's send them to that page. if (id <= 0) { id = Settings.GetNotificationId(); notificationIntent = new Intent(this, typeof(WelcomeActivity)); } else { notificationIntent = new Intent(this, typeof(ConversationActivity)); notificationIntent.PutExtra(ConversationActivity.RecipientId, (long)id); } notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask); var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent); var wearableExtender = new NotificationCompat.WearableExtender() .SetContentIcon(Resource.Drawable.ic_launcher); NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", pendingIntent) .Build(); var builder = new NotificationCompat.Builder(this) .SetContentIntent(pendingIntent) .SetContentTitle(notification.Title) .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.ic_notification) .SetLargeIcon(largeIconBitmap) .SetContentText(notification.Message) .AddAction(reply) .Extend(wearableExtender); // Obtain a reference to the NotificationManager var notif = builder.Build(); notif.Defaults = NotificationDefaults.All; //add sound, vibration, led :) notificationManager.Notify(id, notif); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var intent = new Intent(this, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(this); var title = "I <3 C#"; var message = "Seattle Code Camp rocks!"; var messageLong = "Seattle Code Camp is awesome, I can't wait to see the Xamarin.Forms Demo later! From what I hear it is going to be the best thing ever!"; //Standard Notification FindViewById <Button>(Resource.Id.notification).Click += (sender, e) => { var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true); var notification = builder.Build(); manager.Notify(0, notification); }; //Standard action with action FindViewById <Button>(Resource.Id.notification_action).Click += (sender, e) => { NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .Build(); var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(reply); var notification = builder.Build(); manager.Notify(0, notification); }; //Special Button for Wear FindViewById <Button>(Resource.Id.notification_wear_action).Click += (sender, e) => { NotificationCompat.Action favorite = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_rating_favorite, "Favorite", contentIntent) .Build(); NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .Build(); var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(reply) .Extend(new NotificationCompat.WearableExtender().AddActions(new [] { reply, favorite })); var notification = builder.Build(); manager.Notify(0, notification); }; //Custom Background FindViewById <Button>(Resource.Id.notification_wear_background).Click += (sender, e) => { var action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_rating_favorite, "Favorite", contentIntent) .Build(); var wearableExtender = new NotificationCompat.WearableExtender() .SetHintHideIcon(true) .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background)) .AddAction(action) ; var style = new NotificationCompat.BigTextStyle(); style.BigText(messageLong); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }; //Pages FindViewById <Button>(Resource.Id.notification_wear_pages).Click += (sender, e) => { // Create builder for the main notification var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle("Page 1") .SetContentText("Short message") .SetContentIntent(contentIntent); // Create a big text style for the second page var secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.SetBigContentTitle("Page 2") .BigText(messageLong); // Create second page notification var secondPageNotification = new NotificationCompat.Builder(this) .SetStyle(secondPageStyle) .Build(); // Add second page with wearable extender and extend the main notification var twoPageNotification = new NotificationCompat.WearableExtender() .AddPage(secondPageNotification) .Extend(notificationBuilder) .Build(); // Issue the notification manager.Notify(0, twoPageNotification); }; //Stacked Notifications FindViewById <Button>(Resource.Id.notification_wear_stacked).Click += (sender, e) => { var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background)); // Build the notification, setting the group appropriately var notificaiton1 = new NotificationCompat.Builder(this) .SetContentTitle("New mail from James") .SetContentText(message) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetGroup("group_1") .Extend(wearableExtender) .Build(); var notification2 = new NotificationCompat.Builder(this) .SetContentTitle("New mail from ChrisNTR") .SetContentText("this is subject #1") .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetGroup("group_1") .Extend(wearableExtender) .Build(); manager.Notify(0, notificaiton1); manager.Notify(1, notification2); }; //Voice Input FindViewById <Button>(Resource.Id.notification_wear_voice).Click += (sender, e) => { var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(ExtraVoiceReply) .SetLabel("Reply") .SetChoices(new [] { "Yes", "No", "OK you win" }) .Build(); NotificationCompat.Action reply = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply, "Reply", contentIntent) .AddRemoteInput(remoteInput) .Build(); var wearableExtender = new NotificationCompat.WearableExtender(); wearableExtender.AddAction(reply); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(this) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue) .SetContentTitle(title) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .AddAction(reply) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }; var voiceReply = GetMessageText(Intent); if (!string.IsNullOrWhiteSpace(voiceReply)) { FindViewById <TextView> (Resource.Id.textView1).Text = voiceReply; } }
private void PopUpNotification(int id, string title, string message) { var wearableExtender = new NotificationCompat.WearableExtender () .SetHintHideIcon (true); Bitmap bitmap = null; try{ bitmap = BitmapFactory.DecodeResource (Resources, Resource.Drawable.wear_background); }catch(Exception ex) { } if(bitmap != null) wearableExtender.SetBackground(bitmap); var builder = new NotificationCompat.Builder (this) .SetSmallIcon (Resource.Drawable.ic_notification) .SetContentTitle (title) .SetContentText (message) .Extend(wearableExtender) .SetAutoCancel (true); // Creates an explicit intent for an Activity in your app var 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. var stackBuilder = Android.Support.V4.App.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); var resultPendingIntent = stackBuilder.GetPendingIntent( 0, (int)PendingIntentFlags.UpdateCurrent ); builder.SetContentIntent(resultPendingIntent); var notificationManager = NotificationManagerCompat.From (this); // mId allows you to update the notification later on. notificationManager.Notify(id, builder.Build()); }