这里是 android 中的新东西 :)
我有一个通知生成器,如果应用程序目标版本 > 4.0,它可以正常工作 但是,当我切换到 2.3 时,我在这一行收到一条错误消息,提示“Notificaiton.Builder 无法解析为类型”。
Notification notification = new Notification.Builder(this)
.setSmallIcon(drawable_small)
.setLargeIcon(drawable_big)
.setWhen(System.currentTimeMillis()).setTicker(content_title)
.setContentTitle(content_title).setContentInfo(content_info)
.setContentText(content_text).setContentIntent(pIntent)
.getNotification();
这个问题现在已经解决了! 但是我现在有另一个 它在每个 R(资源)上都给我一个错误,我可以选择导入 R。 如果我导入它,它会在每个资源上给我错误。
setContentView(R.layout.activity_main);
最佳答案
像这样实现您的通知
Notification noti = new NotificationCompat.Builder(context)
.setSmallIcon(icon_small)
.setTicker(message)
.setLargeIcon(largeIcon)
.setWhen(System.currentTimeMillis())
.setContentTitle(title)
.setContentText(message)
.setContentIntent(contentIntent)
//At most three action buttons can be added
.setAutoCancel(true).build();
并将support library v4添加到您的项目中并导入
import android.support.v4.app.NotificationCompat;
NotificationCompat
帮助器,用于以向后兼容的方式访问 API 级别 4
之后引入的 Notification
中的功能。
有关更多信息,请访问:http://developer.android.com/guide/topics/ui/notifiers/notifications.html
关于java - android 2.3 中的通知生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878091/