[英]Xamarin, Android: Customize the standard notification
我們正在使用服務器將推送通知發送到每個電話。 但是我想稍微自定義通知的布局,但是我找不到方法。 通知如下所示:
因此,已經有了一些自定義布局,並帶有一些小提示。 標題和文本來自服務器,“ BOOK OF LIFE”來自應用程序。 所以必須有一種方法可以覆蓋它,對嗎? 我能夠像這樣到達通知的文本:
protected override Android.App.Notification BuildNotification(Context context, PushMessage pushMessage)
{
// TODO customize the notification
pushMessage.Text = "xy";
return base.BuildNotification(context, pushMessage);
}
但是我只是找不到改變布局的方法。 如何覆蓋鈴聲和總體布局?
謝謝 :)
比期望的要容易-這涉及所有GCM通知。
protected override void OnPushReceived(Context context, PushMessage pushMessage)
{
base.OnPushReceived(context, pushMessage);
SendNotification(pushMessage.Message, pushMessage.Title, context);
}
void SendNotification(string message, string title, Context ctx)
{
var intent = new Intent(ctx, typeof(ReadAsset));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(ctx, 0, intent, PendingIntentFlags.OneShot);
var notificationBuilder = new Notification.Builder(ctx)
.SetSmallIcon(Resource.Drawable.icon)
.SetContentTitle(title)
.SetContentText(message)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
var notificationManager = (NotificationManager)ctx.GetSystemService
(Context.NotificationService);
notificationManager.Notify(0, notificationBuilder.Build());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.