私はAndroidが初めてなので、助けが必要です。新しい Notification.Builder インスタンスを構築する方法を理解できないようです。悲しいことに、私がフォローしているチュートリアルでは、古いコンストラクターを使用しています。これは、Android リファレンス ドキュメントを熟読した後、明確に述べられています。押すと簡単な通知が表示されるボタンを作成しました。他の例を見つけた後、すべてのコードは問題ないように見えますが、ビルド メソッドの下で Eclipse で赤い線のエラーが発生します。どんな助けでも大歓迎です:
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);
}
});