我需要一些帮助,因为我是Android新手。我似乎无法理解如何构建新的Notification.Builder实例。令人遗憾的是,我所遵循的教程使用了一个较老的构造函数,在仔细阅读了android参考文档之后清楚地说明了这一点。我创建了一个按钮,当你按下时只提供一个简单的通知。在查找其他示例后,所有代码似乎都可以正常工作,但在构建方法下,Eclipse中出现红线错误。任何帮助将非常感激:Android通知栏构建方法错误
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Context context = Main.this;
Intent intent = new Intent(context, Main.class);
PendingIntent pending = PendingIntent.getActivity(Main.this, 0, intent, 0);
Notification noti = new Notification.Builder(Main.this)
.setTicker("This is important!")
.setContentTitle("PLEASE READ!")
.setContentText("Important message from me!")
.setSmallIcon(android.R.drawable.stat_notify_more)
.setWhen(System.currentTimeMillis())
.setContentIntent(pending)
.build();
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
});
发现请告诉我是日食的错误消息给你? – dymmeh