xamarin forms alarm
C#
public string Create(string title, string message, DateTime scheduleDate, Dictionary<string, string> extraInfo)
{
// Create the unique identifier for this notifications.
var notificationId = Guid.NewGuid().ToString();
// Create the alarm intent to be called when the alarm triggers. Make sure
// to add the id so we can find it later if the user wants to update or
// cancel.
var alarmIntent = new Intent(Application.Context, typeof(NotificationAlarmHandler));
alarmIntent.SetAction(BuildActionName(notificationId));
alarmIntent.PutExtra(TitleExtrasKey, title);
alarmIntent.PutExtra(MessageExtrasKey, message);
// Add the alarm intent to the pending intent.
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent);
// Figure out the alaram in milliseconds.
var utcTime = TimeZoneInfo.ConvertTimeToUtc(scheduleDate);
var epochDif = (new DateTime(1970, 1, 1) - DateTime.MinValue).TotalSeconds;
var notifyTimeInInMilliseconds = utcTime.AddSeconds(-epochDif).Ticks / 10000;
// Set the notification.
var alarmManager = Application.Context.GetSystemService(Context.AlarmService) as AlarmManager;
alarmManager?.Set(AlarmType.RtcWakeup, notifyTimeInInMilliseconds, pendingIntent);
// All done.
return notificationId;
}
[BroadcastReceiver]
internal class NotificationAlarmHandler : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
// Pull out the parameters from the alarm.
var message = intent.GetStringExtra("message");
var title = intent.GetStringExtra("title");
// Create the notification.
var builder = new NotificationCompat.Builder(Application.Context)
.SetContentTitle(title)
.SetContentText(message)
.SetSmallIcon(Resource.Drawable.logo_square_22x22)
.SetAutoCancel(true);
// Set this application to open when the notification is clicked. If the application
// is already open it will reuse the same activity.
var resultIntent = Application.Context.PackageManager.GetLaunchIntentForPackage(Application.Context.PackageName);
resultIntent.SetAction(intent.Action);
resultIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
var resultPendingIntent = PendingIntent.GetActivity(Application.Context, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
builder.SetContentIntent(resultPendingIntent);
// Show the notification.
var notificationManager = NotificationManagerCompat.From(Application.Context);
notificationManager.Notify(0, builder.Build());
}
}
public string Create(string title, string message, DateTime scheduleDate, Dictionary<string, string> extraInfo)
{
// Create the unique identifier for this notifications.
var notificationId = Guid.NewGuid().ToString();
// Create the alarm intent to be called when the alarm triggers. Make sure
// to add the id so we can find it later if the user wants to update or
// cancel.
var alarmIntent = new Intent(Application.Context, typeof(NotificationAlarmHandler));
alarmIntent.SetAction(BuildActionName(notificationId));
alarmIntent.PutExtra(TitleExtrasKey, title);
alarmIntent.PutExtra(MessageExtrasKey, message);
// Add the alarm intent to the pending intent.
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent);
// Figure out the alaram in milliseconds.
var utcTime = TimeZoneInfo.ConvertTimeToUtc(scheduleDate);
var epochDif = (new DateTime(1970, 1, 1) - DateTime.MinValue).TotalSeconds;
var notifyTimeInInMilliseconds = utcTime.AddSeconds(-epochDif).Ticks / 10000;
// Set the notification.
var alarmManager = Application.Context.GetSystemService(Context.AlarmService) as AlarmManager;
alarmManager?.Set(AlarmType.RtcWakeup, notifyTimeInInMilliseconds, pendingIntent);
// All done.
return notificationId;
}
Also in C#:
- Title
- the name scripts does not exist in the current context mvc 5
- Category
- C#
- Title
- convert from xls to xlsx C#
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- image filter
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- c# string to character array
- Category
- C#
- Title
- variables
- Category
- C#
- Title
- c# list tuple
- Category
- C#
- Title
- lista generica como parametro de un metodo en c#
- Category
- C#
- Title
- Unity C# make object face away
- Category
- C#
- Title
- index in foreach c#
- Category
- C#
- Title
- unity persistent data
- Category
- C#
- Title
- foreach syntax c#
- Category
- C#
- Title
- c# how to open file explorer
- Category
- C#
- Title
- void Update
- Category
- C#
- Title
- import regex c#
- Category
- C#
- Title
- c# int
- Category
- C#
- Title
- comments unity c#
- Category
- C#
- Title
- unity check when clicked on object
- Category
- C#
- Title
- c# to vb.net
- Category
- C#
- Title
- c# file exist
- Category
- C#
- Title
- c# postfix increment operator overload
- Category
- C#
- Title
- unity how to tell when a gameobject is colliding
- Category
- C#
- Title
- c# discord bot
- Category
- C#
- Title
- codecademy
- Category
- C#
- Title
- month number to text in c#
- Category
- C#
- Title
- downlaod file and use C#
- Category
- C#
- Title
- c# object list attribute to string
- Category
- C#
- Title
- asp list box
- Category
- C#
- Title
- c# stop loop
- Category
- C#
- Title
- radians to degree c#
- Category
- C#
- Title
- how to make an object move in unity
- Category
- C#
- Title
- c# get every point in a line in matrix
- Category
- C#
- Title
- how to disable a gameObject unity c#
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- initialize enum with another enum c#
- Category
- C#
- Title
- in unity i want to destroy a gameobject when it hits the edge of the screen
- Category
- C#
- Title
- winforms timer c#
- Category
- C#
- Title
- c# multiline comment
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- parse strings into words C#
- Category
- C#
- Title
- unity move character
- Category
- C#
- Title
- unity collider2d contains point
- Category
- C#
- Title
- c# use hashtable check if key exists
- Category
- C#
- Title
- c# send email
- Category
- C#
- Title
- unity prevent system from creation
- Category
- C#
- Title
- c# skip following code in loop
- Category
- C#
- Title
- modal dismiss
- Category
- C#
- Title
- c sharp split string
- Category
- C#
- Title
- c# rsa example
- Category
- C#
- Title
- c# polymorphism
- Category
- C#
- Title
- get number of sundays in a month c#
- Category
- C#
- Title
- unity transfoprm position y change
- Category
- C#
- Title
- Unity how to put IEnumerator in update and loop once with yeild return new waitforseconds
- Category
- C#
- Title
- c# find element in list of list
- Category
- C#
- Title
- c# two dimensional array
- Category
- C#
- Title
- unity making homing rocket
- Category
- C#
- Title
- check if multiple variables are null c#
- Category
- C#
- Title
- unity set sprite transparency
- Category
- C#
- Title
- c# how to run external program with args
- Category
- C#
- Title
- convert string to boolean c#
- Category
- C#
- Title
- c# duplicate object instance
- Category
- C#
- Title
- web api startup add imemory cache object
- Category
- C#
- Title
- how do I attach a player with a navMeshAgent
- Category
- C#
- Title
- how do i limit the amount of prefabs in unity using c# script
- Category
- C#
- Title
- binding c#
- Category
- C#
- Title
- unity 2d joystick controls
- Category
- C#
- Title
- unity how to change max fps
- Category
- C#
- Title
- console.writeline
- Category
- C#
- Title
- C# assigning image location
- Category
- C#
- Title
- get permission to write read file and directory on file system C#
- Category
- C#
- Title
- How to execute script in C#
- Category
- C#
- Title
- inheritance c#
- Category
- C#
- Title
- how to run csharp in visual studio code
- Category
- C#
- Title
- unity deactive all object in list
- Category
- C#
- Title
- c# convert column name to number
- Category
- C#
- Title
- Unity C# add slider into editor
- Category
- C#
- Title
- .net core convert keycollection to array
- Category
- C#
- Title
- asp textarea
- Category
- C#
- Title
- c# cheat sheet
- Category
- C#
- Title
- exception handling c# stack overflow
- Category
- C#
- Title
- how to reference a child object unity
- Category
- C#
- Title
- asp.net textarea disable resize
- Category
- C#
- Title
- asp.net core redirecttoaction with parameters
- Category
- C#
- Title
- how to do a messagebox in c#
- Category
- C#
- Title
- system.io.directorynotfoundexception c#
- Category
- C#
- Title
- sort c#
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- print content of array c#
- Category
- C#
- Title
- c# create dynamic object
- Category
- C#
- Title
- c# loop string array
- Category
- C#
- Title
- c# form set auto scale
- Category
- C#
- Title
- c# substring from index to end
- Category
- C#
- Title
- bundle.config in mvc is missing
- Category
- C#
- Title
- create new object from generic c#
- Category
- C#
- Title
- c# throw new exception
- Category
- C#
- Title
- array c#
- Category
- C#
- Title
- c# set textbox text
- Category
- C#
- Title
- button color uwp c#
- Category
- C#
- Title
- asking for user input integer c#
- Category
- C#