android 设备上未显示通知。 (Azure 通知中心)
Notification not displaying on android device. (Azure notification hub)
我正在尝试向我的 android 模拟器发送推送通知。发送通知时,它收到通知但不显示通知。
我正在使用此代码来显示它。
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);
}
我正在尝试向我的 android 模拟器发送推送通知。发送通知时,它收到通知但不显示通知。
我正在使用此代码来显示它。
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);
}