Trong ứng dụng của tôi, tôi cần hiển thị thông báo cho người dùng. Đoạn mã sau hoạt động tốt bằng cách hiển thị tiêu đề biểu tượng và nội dung trong thanh tiêu đề thiết bị Android.Hiển thị văn bản thông báo trong thanh trạng thái - Android
var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
var uiIntent = new Intent(this, typeof(MainActivity));
var notification = new Notification(Resource.Drawable.AppIcon, title);
notification.Flags = NotificationFlags.AutoCancel;
notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));
notificationManager.Notify(1, notification);
Khi tôi cố gắng xây dựng gói cho việc triển khai ứng dụng, tôi nhận được lỗi sau:
Android.App.Notification.SetLatestEventInfo(Android.Content.Context, string, string, Android.App.PendingIntent)' is obsolete: 'deprecated'
Vì vậy, tôi tìm thấy đoạn mã này, tôi nên sử dụng và nó cho thấy các biểu tượng trong tình trạng thanh không phải là tiêu đề nội dung
Intent resultIntent = new Intent(this, typeof(MainActivity));
PendingIntent pi = PendingIntent.GetActivity(this, 0, resultIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(Forms.Context)
.SetContentIntent(pi)
.SetAutoCancel(true)
.SetContentTitle(title)
.SetSmallIcon(Resource.Drawable.AppIcon)
.SetContentText(desc); //This is the icon to display
NotificationManager nm = GetSystemService(Context.NotificationService) as NotificationManager;
nm.Notify(_TipOfTheDayNotificationId, builder.Build());
Tôi cần phải đặt gì trong đoạn mã mới để hiển thị tiêu đề nội dung trên thanh trạng thái thiết bị Android?
không setcontenttitle làm điều đó? – njzk2
Không, nó không. –
bản sao có thể có của [Cách triển khai các phương pháp thông báo không được chấp nhận] (http://stackoverflow.com/questions/16852270/how-to-implement-the-deprecated-methods-of-notification) – njzk2