因为这个服务器是由其他人处理的,他没有向WSN请求令牌,所以我遵循了一个示例,我正在使用“本地网页”发送通知。
protected void ButtonSendToast_Click(object sender, EventArgs e)
{
try
{
// Get the URI that the Microsoft Push Notification Service returns to the push client when creating a notification channel.
// Normally, a web service would listen for URIs coming from the web client and maintain a list of URIs to send
// notifications out to.
string subscriptionUri = TextBoxUri.Text.ToString();
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri) as HttpWebRequest;
// Create an HTTPWebRequest that posts the toast notification to the Microsoft Push Notification Service.
// HTTP POST is the only method allowed to send the notification.
sendNotificationRequest.Method = "POST";
// The optional custom header X-MessageID uniquely identifies a notification message.
// If it is present, the same value is returned in the notification response. It must be a string that contains a UUID.
// sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>");
// Create the toast message.
string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>" + TextBoxTitle.Text.ToString() + "</wp:Text1>" +
"<wp:Text2>" + TextBoxSubTitle.Text.ToString() + "</wp:Text2>" +
"<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
"</wp:Toast> " +
"</wp:Notification>";
// Set the notification payload to send.
byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);
// Set the web request content length.
sendNotificationRequest.Headers.Add("Authorization", String.Format("Bearer {0}", "EgAdAQMAAAAEgAAAC4AATIYp8fmpjFpbdnRTjf2qfP/GqZ8Bbb62bH6N+0MhSztcV/wXfv9aVjiwbVgF5EX0fgBXC6LvJCpl1+ze7ts9h5je4e1QekryEFqfWl36BtTBnmWqBFk0WmwxpdIgGqhVjAtRdnJ3ODnFSBCfd7dq8nFiFTFDxPcTXhdDbu9W3BKMAFoAjAAAAAAAHFAXTMH+bVbB/m1W60gEAA8AMTkwLjE5My42OS4yMzMAAAAAAF0AbXMtYXBwOi8vcy0xLTE1LTItMTU5OTEyNjk1NS0zODAwNDMxNzQ0LTk2OTg4NTEzNi0xNjkxMDU1MjI4LTcwOTcyNTQ0NC00MDYxNzA4MDczLTI0Mzg0MzM1MzQA"));
sendNotificationRequest.ContentLength = notificationMessage.Length;
sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.Headers.Add("X-WNS-Type", "wns/toast");
using (Stream requestStream = sendNotificationRequest.GetRequestStream())
{
requestStream.Write(notificationMessage, 0, notificationMessage.Length);
}
// Send the notification and get the response.
HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
string notificationStatus = response.Headers["X-NotificationStatus"];
string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
// Display the response from the Microsoft Push Notification Service.
// Normally, error handling code would be here. In the real world, because data connections are not always available,
// notifications may need to be throttled back if the device cannot be reached.
TextBoxResponse.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
}
catch (Exception ex)
{
TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
}
}
现在,在我的应用程序中,我请求了通道uri和一个处理程序,当该通道接收到推送时,该处理程序将被调用
PushNotificationChannel channel = null;
try
{
channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
Debug.WriteLine(channel.Uri);
if (channel.Uri != null)
{
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values.Remove("PushToken");
localSettings.Values["PushToken"] = channel.Uri;
channel.PushNotificationReceived += channel_PushNotificationReceived;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
async void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
{
String notificationContent = String.Empty;
notificationContent = e.ToastNotification.Content.GetXml();
Debug.WriteLine(notificationContent);
}
到目前为止,一切都很好:当我的应用程序正在运行时和当我的应用程序关闭时,我都会收到一个通知。但上面只写着“新通知”,我点开后什么也没发生。
我尝试添加一个事件
e.ToastNotification.Activated += ToastNotification_Activated;
但这不起作用,在阅读了20个文档后,我对toast模板非常困惑,我如何使用它来显示我从服务器接收到的内容
那么,真正做到这一点的方法是什么,在吐司中显示推送中收到的一些数据,并在用户点击时使app“启动/转到某个页面”?
应用程序要转到某个页面
自Windows8/8.1以来,应用程序一直被期望在用户点击该应用程序的烤面包通知时处理激活--应用程序应该通过执行导航和显示特定于烤面包的UI来响应。这是通过包含在toast有效负载中的激活字符串来实现的,该字符串随后作为激活事件中的参数传递给应用程序。
要导航到某个页面,需要重写app.xaml.cs中的OnActivated事件,并处理string参数。
我想知道是否有标志和参数可以通过单击通知托盘中的推送通知来告诉我用户是否启动了活动/应用程序。 我在 C2DM 接收器中的代码.java 我试着设定 但当该应用程序启动时,其意图中没有额外的内容。 我的mainactivity的onCreate函数中的代码 我得到的输出是onCreate - bundle没有额外的内容。所以多余的部分没有通过。 那么还有其他方法吗?在iOS中很容易
如何统计推送通知并将其显示在主屏幕应用程序图标上 公共无效(上下文上下文,意图意图){}
我通过FCM实现了推送通知。当应用程序从我的服务器获得一个新的通知时,通知面板会被我在notificationcompat.builder中设置的图标所注意,但消息不会作为弹出预览。我尝试设置优先级,样式,类别,但通知仍然没有显示。当我滚动时,我可以看到通知。 我在两种不同的设备操作系统(6.0.1和5.0.1)上尝试了这个应用程序,也是我的后端C#解决方案--两种方法都不弹出通知消息和通知 Fi
我想为一个聊天应用程序实现FCM推送通知服务,我遵循Firebase文档中的步骤,当通知从Firebase控制台发送到我的设备时,我会得到通知。当我尝试使用http post to https://FCM.googleapis.com/FCM/send通过FCM将通知通过服务器端发送到设备时: 当应用程序处于活动状态并且我正在将此通知发送到我的设备时,Im在我的控制台日志中收到以下消息,所以我认为
是否可以知道应用程序是否从消息推送中启动/打开? 我想发射活动可以在这里捕捉到: 然而,当应用程序处于后台时,如何从推送通知中检测到它被打开?