[DllExport(CallingConvention.StdCall)]
class LiveTileHelper
{
[DllExport(CallingConvention.StdCall)]
public static string UpdatePrimaryTile(string text, int durationSeconds = 10)
{
var template = Windows.UI.Notifications.TileTemplateType.TileSquare150x150Block;
var tileXml = Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(template);
var tileTextAttributes = tileXml.GetElementsByTagName("text");
tileTextAttributes[0].AppendChild(tileXml.CreateTextNode(text));
var tileNotification = new Windows.UI.Notifications.TileNotification(tileXml);
tileNotification.ExpirationTime = DateTime.Now.AddSeconds(durationSeconds);
Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
return "Ok";
}
}
private static ScheduledToastNotification CreateAScheduleToast(
string toastTitle,
string toastContent,
DateTime scheduleTime)
{
var doc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var strings = doc.GetElementsByTagName("text");
strings[0].AppendChild(doc.CreateTextNode(toastTitle));
strings[1].AppendChild(doc.CreateTextNode("Scheduled: " + toastContent));
var toast = new ScheduledToastNotification(doc, scheduleTime);
return toast;
}
[DllExport(CallingConvention.StdCall)]
public static string NotifyWithDelay(string toastTitle, string toastContent, int delayinMilliseconds)
{
try
{
var scheduleTime = DateTime.Now.AddMilliseconds(delayinMilliseconds);
ScheduledToastNotification toast = CreateAScheduleToast(toastTitle, toastContent, scheduleTime);
// Add to the schedule.
ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
}
catch (AggregateException ex)
{
return "Exception:" + ex.ToString() + " exMessage:" + ex.Message;
}
return "Ok";
}
Note the output folder of the dll because you will have to copy it to the Unity project's folder. Generally it is something like \bin\x64\Release .
Please refer to the previous article for the full steps.
DllImport
and
extern static
before. Especially if you use simple types for parameters. Here are examples:
[DllImport("dotNETClassLibraryUsingUWPAPIs")]
extern static string NotifyWithDelay(string toastTitle, string toastContent, int delayinMilliseconds);
[DllImport("dotNETClassLibraryUsingUWPAPIs")]
extern static string UpdatePrimaryTile(string text, int durationSeconds);
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
string output = NotifyWithDelay("Schedule Toast title",
"Unity toast sent at " + System.DateTime.Now.ToLongTimeString(), 5000);
}
if (Input.GetKeyDown(KeyCode.T))
{
string output = UpdatePrimaryTile("Updated at "
+ System.DateTime.Now.ToLongTimeString(), 20);
}
}
To test the app, you have to first install the auto-generated.cer certificate in the Trusted People container for local machine certificates.
Again, the full steps are described in the previous article .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.