[英]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.