我有一个小问题,但不明白如何摆脱这个.
我创建了一个用于提供通知的类,但这些行被标记为已弃用:
...
Notification notification = new Notification(icon, text, time); // deprecated in API level 11
...
notification.setLatestEventInfo(this, title, text, contentIntent); // deprecated in API level 11
...
Run Code Online (Sandbox Code Playgroud)
替代方法是:
...
Notification noti = new Notification.Builder(mContext)
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.build(); // available from API level 11 and onwards
...
Run Code Online (Sandbox Code Playgroud)
我可以编写类似的代码:
if(API_level < 11)
{
...
Notification notification = new Notification(icon, text, time); // deprecated in API level 11
...
notification.setLatestEventInfo(this, title, text, contentIntent); // deprecated …Run Code Online (Sandbox Code Playgroud)