I am using a CrossPlateForm
technique to Create Android and IOS app using xamarine, i want to send push notification when my application is in sleep mode, this is my method
我正在使用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);
}
the count will come from a service which i wrote in portable project, when i tried to write pushNotification
method in portable project Notification.Builder
i cannot access Notification
namespace. I want to trigger a method in portable
project whenever applications to sleepmode and show the count using pushNotification
, or is their any alternative way to do this?
计数将来自我在便携式项目中编写的服务,当我尝试在便携式项目Notification.Builder中编写pushNotification方法时,我无法访问Notification命名空间。我希望每当应用程序进入sleepmode并使用pushNotification显示计数时在可移植项目中触发一个方法,或者他们是否有其他方法可以执行此操作?
1 个解决方案
#1
0
You should try call your method on App.cs inside the OnSleep function:
您应该尝试在OnSleep函数内的App.cs上调用您的方法:
public class App : Application
{
{
...
}
protected override void OnSleep ()
{
// Your method here
}
#1
0
You should try call your method on App.cs inside the OnSleep function:
您应该尝试在OnSleep函数内的App.cs上调用您的方法:
public class App : Application
{
{
...
}
protected override void OnSleep ()
{
// Your method here
}