我使用CrossPlateForm
技术使用xamarine创建Android和IOS应用程序,我想在我的应用程序处于睡眠模式时发送推送通知,
这是我的方法
public void pushNotifications(int count)
{
Notification.Builder builder = new Notification.Builder(this)
.SetContentTitle("new Messages")
.SetContentText("Hello World! This is my first notification!")
.SetSmallIcon(Resource.Drawable.icon);
// Instantiate the Inbox style:
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
// Set the title and text of the notification:
builder.SetContentTitle(count+" new messages");
//builder.SetContentText("chimchim@xamarin.com");
// Plug this style into the builder:
builder.SetStyle(inboxStyle);
// Build the notification:
Notification notification = builder.Build();
// Get the notification manager:
NotificationManager notificationManager =
GetSystemService(Context.NotificationService) as NotificationManager;
// Publish the notification:
const int notificationId = 0;
notificationManager.Notify(notificationId, notification);
}
计数将来自我在便携式项目中编写的服务,当我尝试在可移植项目pushNotification
中编写Notification.Builder
方法时,我无法访问Notification
命名空间。我希望每当应用程序进入sleepmode并使用portable
显示计数时在pushNotification
项目中触发一个方法,或者他们是否有其他方法可以执行此操作?
答案 0 :(得分:0)
你应该尝试在OnSleep函数中的App.cs上调用你的方法:
public class App : Application
{
{
...
}
protected override void OnSleep ()
{
// Your method here
}