Android 可扩展通知
我将通过以下链接创建通知: 这是我的代码:Android 可扩展通知,android,xamarin,xamarin.android,Android,Xamarin,Xamarin.android,我将通过以下链接创建通知: 这是我的代码: Notification.BigTextStyle textStyle = new Notification.BigTextStyle(); // Fill it with text: string longTextMessage = "I went up one pair of stairs."; longTextMessage += " / Just like me. ";
Notification.BigTextStyle textStyle = new Notification.BigTextStyle();
// Fill it with text:
string longTextMessage = "I went up one pair of stairs.";
longTextMessage += " / Just like me. ";
//...
textStyle.BigText(longTextMessage);
// Set the summary text:
textStyle.SetSummaryText("The summary text goes here.");
// Plug this style into the builder:
//creo la notifica:
var builder = new NotificationCompat.Builder(instance, "enter")
.SetSmallIcon(global::Android.Resource.Drawable.IcDialogInfo)
.SetContentIntent( pending)
.SetDefaults((int)NotificationDefaults.Sound)
.SetDefaults((int)NotificationDefaults.Vibrate)
.SetNumber(count)
.SetAutoCancel(true)
.SetContentTitle("Proximity") // Set the title
.SetContentText($"benvenuto nel beacon di colore {deskOwner},{count}")
.SetStyle(textStyle)
.Build();
count++;
// Get the notification manager:
NotificationManager notificationManager = instance.GetSystemService(Context.NotificationService) as NotificationManager;
// Pubblico la notifica:
const int notificationId = 0;
notificationManager.Notify(notificationId, builder);
return null;
}
但是in.SetStyle(textStyle)给了我以下错误:
'无法从'Android.App.Notification.BigTextStyle'转换为'Android.Support.V4.App.NotificationCompat.Style'
我怎样才能修好它 它不起作用的原因是您正在使用NotificationCompat,但没有使用NotificationCompat.BigTextStyle,请尝试以下方法:
NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
// Fill it with text:
string longTextMessage = "I went up one pair of stairs.";
longTextMessage += " / Just like me. ";
//...
textStyle.BigText(longTextMessage);
// Set the summary text:
textStyle.SetSummaryText("The summary text goes here.");
它不起作用的原因是您使用的是NotificationCompat,而不是NotificationCompat.BigTextStyle,请尝试以下操作:
NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
// Fill it with text:
string longTextMessage = "I went up one pair of stairs.";
longTextMessage += " / Just like me. ";
//...
textStyle.BigText(longTextMessage);
// Set the summary text:
textStyle.SetSummaryText("The summary text goes here.");