简体   繁体   English

Xamarin,Android:自定义标准通知

[英]Xamarin, Android: Customize the standard notification

We are using our server to send push notifications to each individual phone. 我们正在使用服务器将推送通知发送到每个电话。 But I'd like to customize the layout of the notification a little but I couldnt find out how. 但是我想稍微自定义通知的布局,但是我找不到方法。 The notification looks like this: 通知如下所示: 在此处输入图片说明

So there is somewhat a custom layout already there, with this little bell. 因此,已经有了一些自定义布局,并带有一些小提示。 The title and the text come from the server and the "BOOK OF LIFE" from the app. 标题和文本来自服务器,“ BOOK OF LIFE”来自应用程序。 So there must be a way to override this, right? 所以必须有一种方法可以覆盖它,对吗? I was able to get to the notification's text like this: 我能够像这样到达通知的文本:

    protected override Android.App.Notification BuildNotification(Context context, PushMessage pushMessage)
    {
        // TODO customize the notification
        pushMessage.Text = "xy";
        return base.BuildNotification(context, pushMessage);
    }

But I just cannot find a way to change the layout. 但是我只是找不到改变布局的方法。 How would I override the bell and the general layout? 如何覆盖铃声和总体布局?

Thanks :) 谢谢 :)

Easier than hoped - this regards all GCM notifications. 比期望的要容易-这涉及所有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM