NoSuchMethodError Notification.Builder.build()

RMa*_*nik 3 android

   Notification noti = new Notification.Builder(context)
            .setContentTitle("TITLE").setContentInfo("INFO")
            .build();
notificationManager.notify(ID,noti);
Run Code Online (Sandbox Code Playgroud)

我从谷歌页面的样本有问题.我有异常NoSuchMethodError我不知道发生了什么,所以我使用旧的弃用方法与通知noti.setLatestEventInfo,但我敢肯定还有另一种解决方案.有任何想法吗?

wan*_*934 11

Notification.Builder.build()是API级别16.

在4.0.4中,您应该使用getNotification().

或者你最好使用NotificationCompat.