我喜欢为我的消息应用程序提供一个 stck 类型的通知,它是一个网络应用程序。 我的通知正在运行。但是每次收到新通知时,之前的通知都会消失,然后会出现新通知。当我用谷歌搜索时,我发现可以使用 setGroup。但是当我使用它时它显示
对于类型 NotificationCompat.Builder 未定义 setGroup()。
我的通知函数是:
public void CreateNotification(String msg)
{
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);
Intent notificationIntent = new Intent(AndroidMobileAppSampleActivity.this, AndroidMobileAppSampleActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(AndroidMobileAppSampleActivity.this, 0, notificationIntent, 0);
NotificationManager notificationManager = (NotificationManager) AndroidMobileAppSampleActivity.this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new NotificationCompat.Builder(AndroidMobileAppSampleActivity.this)
.setSmallIcon(R.drawable.icon)
.setTicker("New message from "+msg)
.setWhen(System.currentTimeMillis())
.setContentTitle("Mybuzzin")
.setContentText(msg)
.setContentIntent(contentIntent)
//At most three action buttons can be added
.setAutoCancel(true).build();
noti.defaults |= Notification.DEFAULT_SOUND;
noti.defaults |= Notification.DEFAULT_VIBRATE;
noti.flags |=Notification.FLAG_SHOW_LIGHTS| Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notifyID, noti);
}
最佳答案
我遇到了同样的问题,但几个小时后我解决了很多其他问题。我假设您也在使用 Eclipse,否则解决方案会有所不同。
您必须在 SDK 管理器中更新您的 android。特别是 Android SDK Build-Tools,之后你必须安装 API20。 现在您必须按照此处所述更新您的 ADT:https://stackoverflow.com/a/24437737/2061089 更新后不用担心,它现在可以正常工作了。在安装更新之前,您必须删除所有要更新的组件。
重新启动 eclipse 后,您只需更新项目中的所有支持(v4、v7 和 v13)包。取决于您使用的是什么。
完成。现在一切都是最新的,一切正常。
希望对您有所帮助!
关于android - NotificationCompat.Builder 类型未定义 setGroup()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25473771/