【发布时间】:2014-07-16 18:19:22
【问题描述】:
我正在尝试让我的应用发出通知,但由于最低 api 级别为 11,我必须使用此代码:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
// call something for API Level 16+
Notification noti;
noti = new Notification.Builder(this)
.setContentTitle("New Notification from LCD")
.setContentText("content")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.addAction(R.drawable.ic_launcher, "Option1", pIntent)
.addAction(R.drawable.ic_launcher, "Option2", pIntent)
.addAction(R.drawable.ic_launcher, "Option3",
pIntent).build();
NotificationManager nmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide notification
noti.flags |= Notification.FLAG_AUTO_CANCEL;
nmanager.notify(0, noti);
}
我为 16 级以下的 API 级别设置了另一个,使用 .getNotification() 而不是 .build()。
即使在那之后我也收到了Call requires API level 16 (current min is 11) 错误。我该怎么做才能解决这个问题?
编辑:忘了添加,.getNotification 行给出了一个黄色错误,说The method getNotification() from the type Notification.Builder is deprecated
【问题讨论】:
标签: android notifications