相关疑难解决方法(0)

如何实现Notification的弃用方法

我有一个小问题,但不明白如何摆脱这个.

我创建了一个用于提供通知的类,但这些行被标记为已弃用:

...
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)

android android-notifications

31
推荐指数
2
解决办法
5万
查看次数

标签 统计

android ×1

android-notifications ×1