[英]Xamarin.Forms Android Local Notification Not Sending
我已經遵循了Xamarin演練,但對我來說不起作用。 代碼完全通過了此過程,但是它從不發送通知。 它永遠不會顯示在我的模擬器或設備上。
我不知道發生了什么。
public override void OnReceive(Context context, Intent intent)
{
string message = intent.GetStringExtra("message");
string title = intent.GetStringExtra("title");
int id = int.Parse(intent.GetStringExtra("id"));
//Generate a notification with just short text and small icon
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.SetAutoCancel(true) // Dismiss from the notif. area when clicked
.SetContentTitle(title) // Set its title
.SetContentText(message); // The message to display.
NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
notificationManager.Notify(id, builder.Build());
任何幫助或鏈接將非常有幫助。 我完全迷路了; 已經為此工作了大約14個小時,並且在Google上找不到任何幫助。
回答我的問題:您必須設置一個圖標,才能正確構建和發送通知。 雖然,它不會因為沒有一個而發送錯誤。
簡短版本:需要添加
.SetSmallIcon(Resource.Drawable.icon);
在通知中添加圖標。
Notification.Builder builder = new Notification.Builder (this)
.SetContentTitle ("Title")
.SetContentText ("Message")
.SetSmallIcon (Resource.Drawable.ic_notification);
Notification notification = builder.Build();
NotificationManager notificationManager =
GetSystemService (Context.NotificationService) as NotificationManager;
const int notificationId = 0;
notificationManager.Notify (notificationId, notification);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.