private void NotifyNotification() { // Pass the current button press count value to the next activity: var valuesForActivity = new Bundle(); valuesForActivity.PutInt(COUNT_KEY, 1); // When the user clicks the notification, SecondActivity will start up. var resultIntent = new Intent(this, typeof(Home)); // Pass some values to SecondActivity: resultIntent.PutExtras(valuesForActivity); // Construct a back stack for cross-task navigation: var stackBuilder = TaskStackBuilder.Create(this); stackBuilder.AddParentStack(Class.FromType(typeof(Home))); stackBuilder.AddNextIntent(resultIntent); // Create the PendingIntent with the back stack: var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); // Build the notification: var builder = new NotificationCompat.Builder(this, CHANNEL_ID) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent. .SetContentTitle("Confirmed") // Set the title .SetNumber(1) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.logo) // This is the icon to display .SetContentText("Your order is confirmed by EatIt.") // the message to display. .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)); // Finally, publish the notification: var notificationManager = NotificationManagerCompat.From(this); notificationManager.Notify(NOTIFICATION_ID, builder.Build()); Console.WriteLine("Done"); try { //cooking time: 180 sec Thread.Sleep(10000); } catch (InterruptedException e) { e.PrintStackTrace(); } resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); // Build the notification: builder = new NotificationCompat.Builder(this, CHANNEL_ID) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent. .SetContentTitle("Order Prepared!") // Set the title .SetNumber(1) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.logo) // This is the icon to display .SetContentText("Your order is Prepared by EatIt.") // the message to display. .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)); // Finally, publish the notification: notificationManager = NotificationManagerCompat.From(this); notificationManager.Notify(NOTIFICATION_ID, builder.Build()); try { //cooking time: 180 sec Thread.Sleep(10000); } catch (InterruptedException e) { e.PrintStackTrace(); } //Order Packaged resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); // Build the notification: builder = new NotificationCompat.Builder(this, CHANNEL_ID) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent. .SetContentTitle("Order Packed!") // Set the title .SetNumber(1) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.logo) // This is the icon to display .SetContentText("Your order is Packed by EatIt.") // the message to display. .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)); // Finally, publish the notification: notificationManager = NotificationManagerCompat.From(this); notificationManager.Notify(NOTIFICATION_ID, builder.Build()); }
public void CreateNotification(int notificationType, int notificationId) { string notificationTitle = ""; string notificationMsg = ""; NotificationCompat.Builder builder = new NotificationCompat.Builder(Forms.Context); // Checked In Notification if (notificationType == NOTIFICATION_TYPE_USER_CHECKED_IN) { notificationTitle = Txt.NOTIFICATION_TITLE_CHECKED_IN; notificationMsg = Txt.NOTIFICATION_TITLE_CHECKED_IN; // Create an Intent to open the main activity, if there is an existing activity it must be killed and // for the new activity to take place Intent resultIntent = new Intent(Forms.Context, typeof(MainActivity)); resultIntent.PutExtra(AndroidMethods.PARAM_SELECTED_LOCATION_ID, App.checkedInLocationID); resultIntent.PutExtra(AndroidMethods.PARAM_LAST_SESSION_PID, Android.OS.Process.MyPid()); resultIntent.AddFlags(ActivityFlags.SingleTop); // Construct a back stack for cross-task navigation TaskStackBuilder stackBuilder = TaskStackBuilder.Create(Forms.Context); stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity))); stackBuilder.AddNextIntent(resultIntent); // Create the PendingIntent with the back stack PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); builder.SetContentTitle(notificationTitle) // Notification title .SetContentText(notificationMsg) // Notification message .SetSmallIcon(Resource.Drawable.ico_alert) // Notification icon .SetAutoCancel(true) // Dismiss from the notif. area when clicked .SetContentIntent(resultPendingIntent) // Start 2nd activity when the intent is clicked. .SetNumber(1); // Display the count in the Content Info // Checked Out Notification } else if (notificationType == NOTIFICATION_TYPE_USER_CHECKED_OUT) { notificationTitle = Txt.NOTIFICATION_TITLE_CHECKED_OUT; notificationMsg = Txt.NOTIFICATION_BODY_CHECKED_OUT; builder.SetContentTitle(notificationTitle) // Notification title .SetContentText(notificationMsg) // Notification message .SetSmallIcon(Resource.Drawable.ico_alert) // Notification icon .SetAutoCancel(true) // Dismiss from the notif. area when clicked .SetNumber(1); // Display the count in the Content Info // Welcome Back Notification } else if (notificationType == NOTIFICATION_TYPE_WELCOME_BACK) { notificationTitle = Txt.NOTIFICATION_TITLE_WELCOME_BACK; notificationMsg = Txt.NOTIFICATION_BODY_WELCOME_BACK; builder.SetContentTitle(notificationTitle) // Notification title .SetContentText(notificationMsg) // Notification message .SetSmallIcon(Resource.Drawable.ico_alert) // Notification icon .SetAutoCancel(true) // Dismiss from the notif. area when clicked .SetNumber(1); // Display the count in the Content Info } NotificationManager notificationManager = (NotificationManager)Forms.Context.GetSystemService( Context.NotificationService ); notificationManager.Notify(notificationId, builder.Build()); }
public override void OnReceive(Context context, Intent intent) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context); String medicineName = prefs.GetString("medicineName", ""); int ringtoneidnr = prefs.GetInt("ringtoneidnr", 1); // Pass the current button press count value to the next activity: //Bundle valuesForActivity = new Bundle(); //valuesForActivity.PutInt("count", count); //valuesForActivity.PutString("name", "Rose"); ISharedPreferencesEditor editor = prefs.Edit(); editor.PutInt("count", count); editor.PutString("name", "Rose"); editor.Apply(); Intent resultIntent = new Intent(context, typeof(MeldingErna)); // Pass some values to SecondActivity: // resultIntent.PutExtras(valuesForActivity); count++; // Construct a back stack for cross-task navigation: TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context); stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MeldingErna))); stackBuilder.AddNextIntent(resultIntent); // Create the PendingIntent with the back stack: PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); long[] vibrate = new long[] { 1000, 1000, 1000, 1000, 1000 }; //Android.Net.Uri uri = Android.Net.Uri.Parse("android.resource://" + context.PackageName + "/" // + Resource.Raw.ialarm); // Build the notification: This is required to show notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetAutoCancel(true) // Dismiss from the notif. area when clicked .SetContentIntent(resultPendingIntent) // Start 2nd activity when the intent is clicked. .SetContentTitle("Alarm :" + medicineName) // Set its title .SetVibrate(vibrate) //.SetSound(uri) .SetNumber(count) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.Icon) // Display this icon .SetContentText(String.Format( "The button has been clicked {0} times.", count)); // The message to display. //throw new NotImplementedException(); if (ringtoneidnr == 1) { Android.Net.Uri uri = Android.Net.Uri.Parse("android.resource://" + context.PackageName + "/" + Resource.Raw.ialarm); builder.SetSound(uri); } else if (ringtoneidnr == 2) { Android.Net.Uri seconduri = Android.Net.Uri.Parse("android.resource://" + context.PackageName + "/" + Resource.Raw.radar); builder.SetSound(seconduri); } else if (ringtoneidnr == 3) { Android.Net.Uri thirduri = Android.Net.Uri.Parse("android.resource://" + context.PackageName + "/" + Resource.Raw.sunalarm); builder.SetSound(thirduri); } NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); notificationManager.Notify(ButtonClickNotificationId, builder.Build()); }