如果我的设备连续多次无法推送通知,我希望将其视为已卸载,并从fcmtoken表中删除它。如果无法发出通知,我如何从FCM服务器接收响应?
代码:OnMessageReceived
public override void OnMessageReceived(RemoteMessage message)
{
try
{
Log.Debug(TAG, "From: " + message.From);
Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
// Create an intent to open the MainActivity when the notification is clicked
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
// Build the notification
if (message.GetNotification() != null)
{
string title = message.GetNotification().Title;
string body = message.GetNotification().Body;
var notificationBuilder = new NotificationCompat.Builder(this, PRIMARY_CHANNEL)
.SetSmallIcon(Resource.Drawable.splash_logo)
.SetContentTitle(title)
.SetContentText(body)
.SetAutoCancel(true)
.SetPriority(NotificationCompat.PriorityHigh)
.SetContentIntent(pendingIntent);
var notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(notificationId++, notificationBuilder.Build());
}
}
catch (System.Exception ex)
{
Log.Error(TAG, ex.Message);
}
}
1条答案
按热度按时间332nm8kg1#
我不知道如何为客户端做到这一点,但这个方法对我的服务器工作。