-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyNotification.cs
151 lines (126 loc) · 5.14 KB
/
MyNotification.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Threading.Tasks;
using Windows.UI.Notifications;
namespace My_Date_Countdown
{
// Make sure to install Microsoft.Toolkit.Uwp.Notifications on NuGet
class MyNotification
{
const string tag = "tag";
public MyNotification()
{
}
public MyNotification ToastNotify(string title = "", string content = "", string tag = tag)
{
ToastVisual visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = title
},
new AdaptiveText()
{
Text = content
},
}
}
};
ToastContent toastContent = new ToastContent()
{ Visual = visual };
var toast = new ToastNotification(toastContent.GetXml())
{
Tag = tag
};
ToastNotificationManager.CreateToastNotifier().Show(toast);
return this;
}
public void ClearTile()
{
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
}
private async Task<bool> CheckTileSupport()
{
// Check for pin-to-start support
// https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/primary-tile-apis
Windows.ApplicationModel.Core.AppListEntry entry = (await Windows.ApplicationModel.Package.Current.GetAppListEntriesAsync())[0];
bool isSupported = Windows.UI.StartScreen.StartScreenManager.GetDefault().SupportsAppListEntry(entry);
return isSupported;
}
public async Task<bool> CheckTileExist()
{
//https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/primary-tile-apis#check-whether-youre-currently-pinned
// Get your own app list entry
Windows.ApplicationModel.Core.AppListEntry entry = (await Windows.ApplicationModel.Package.Current.GetAppListEntriesAsync())[0];
// Check if your app is currently pinned
bool isPinned = await Windows.UI.StartScreen.StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry);
return isPinned;
}
public async void PinTile()
{
// https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/primary-tile-apis#pin-your-primary-tile
// Get your own app list entry
Windows.ApplicationModel.Core.AppListEntry entry = (await Windows.ApplicationModel.Package.Current.GetAppListEntriesAsync())[0];
// And pin it to Start
await Windows.UI.StartScreen.StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
}
public async Task<bool> CheckToastPermission()
{
return await new AppUtility().requestStartupTaskAsync("DateCountdownStartupId");
}
public MyNotification TileNotify(string title = "", string content = "")
{
// Construct the tile content
TileContent tileContent = new TileContent()
{
Visual = new TileVisual()
{
TileMedium = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
Children =
{
new AdaptiveText()
{
Text = title,
},
new AdaptiveText()
{
Text = content,
HintStyle = AdaptiveTextStyle.CaptionSubtle
}
}
}
},
TileWide = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
Children =
{
new AdaptiveText()
{
Text = title,
HintStyle = AdaptiveTextStyle.Title
},
new AdaptiveText()
{
Text = content,
HintStyle = AdaptiveTextStyle.Body
}
}
}
}
}
};
var notification = new TileNotification(tileContent.GetXml());
TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
return this;
}
}
}