我有以下代码,其给我的“build()未在Notification.Builder中定义”错误。
Notification.Builder notificationBuilder = new Notification.Builder(mApplicationContext)
.setContentIntent(pendingIntent)
.setContent(mContentView)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setAutoCancel(true);
// Send the notification
NotificationManager mNotificationManager = (NotificationManager) mParentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
最佳答案
由于您的目标是API 19和最小API 13(HC),因此需要使用NotificationCompat.Builder-尝试:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
mApplicationContext);
Notification notification = notificationBuilder.setContentIntent(pendingIntent)
.setContent(mContentView)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setAutoCancel(true).build();
// Send the notification
NotificationManager mNotificationManager = (NotificationManager) mParentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, notification);
https://stackoverflow.com/questions/26706739/