通知未在android设备上显示。(Azure通知中心)
我正在尝试向我的android模拟器发送推送通知。发送通知时,它接收通知,但不显示通知通知未在android设备上显示。(Azure通知中心),azure,push-notification,xamarin.android,android-notifications,Azure,Push Notification,Xamarin.android,Android Notifications,我正在尝试向我的android模拟器发送推送通知。发送通知时,它接收通知,但不显示通知 void SendNotification(string messageBody) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetAct
void SendNotification(string messageBody)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.SetContentTitle("FCM Message")
.SetSmallIcon(Resource.Drawable.icon)
.SetContentText(messageBody)
.SetChannelId("my-chanel")
.SetAutoCancel(true)
.SetContentIntent(pendingIntent)
.SetSound();
var notificationManager = NotificationManager.FromContext(this);
notificationManager.Notify(0, notificationBuilder.Build());
}
我用这个代码来显示它
void SendNotification(string messageBody)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.SetContentTitle("FCM Message")
.SetSmallIcon(Resource.Drawable.icon)
.SetContentText(messageBody)
.SetChannelId("my-chanel")
.SetAutoCancel(true)
.SetContentIntent(pendingIntent)
.SetSound();
var notificationManager = NotificationManager.FromContext(this);
notificationManager.Notify(0, notificationBuilder.Build());
}
但是当收到通知时,什么也没有发生,我的设备日志告诉我:
[Mono] Assembly Ref addref ODEON.Android[0xa31db5c0] -> System.Core[0xa1f2f900]: 7
[MyFirebaseMsgService] From: 241571420247
[MyFirebaseMsgService] noti:
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_boolean_method'.
[Mono] Probing 'java_interop_jnienv_call_boolean_method'.
[Mono] Found as 'java_interop_jnienv_call_boolean_method'.
[Mono] Assembly Ref addref Xamarin.Android.Support.Compat[0xa31dca60] -> Java.Interop[0xa1f2f780]: 8
[Notification] Use of stream types is deprecated for operations other than volume control
[Notification] See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
谁能告诉我为什么它不显示。
提前谢谢 如果调用发送通知方法,请使用以下代码显示通知:
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
.SetContentTitle("Title")
.SetContentText(messageBody)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(0, notificationBuilder.Build());
另外,如果您有Android V 8+设备,我相信您会注意到这一点,那么您正在注册MainActivity OnCreate方法中的通知通道
void CreateNotificationChannel()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// Notification channels are new in API 26 (and not a part of the
// support library). There is no need to create a notification
// channel on older versions of Android.
return;
}
var channel = new NotificationChannel(CHANNEL_ID, "FCM Notifications", NotificationImportance.Default)
{
Description = "Firebase Cloud Messages appear in this channel"
};
var notificationManager = (NotificationManager) GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
void CreateNotificationChannel()
{
if(Build.VERSION.SdkInt
上面写着:当前上下文中不存在通道ID,运行在nexus\u galaxy(API 27)模拟器上的im通道ID可以是您想要的任何字符串,只要确保在需要通道ID时使用相同的内容:内部静态只读字符串通道ID=“my\u notification\u CHANNEL”代码>它可以工作(Y),但现在当我向设备发送通知时,我无法在文本中生成动态内容。例如,如何从PayloadThank设置ContentText,以防您遇到任何问题,请随时回复。