Reputation: 3879
I need some help as I am new to Android. I cannot seem to grasp how to build a new Notification.Builder instance. Sadly the tutorial I am following uses an older constructor, which after perusing the android reference docs clearly states. I have created a button that when you press just provides a simple notification. All the code seems ok after finding other examples, but I get an red line error in Eclipse under the build method. Any help would be much appreciated:
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);
}
});
Upvotes: 2
Views: 993
Reputation: 775
If you are using android.support.v4, use NotificationCompat found in Android v4 Support
Upvotes: 0
Reputation: 30994
Notification.Builder.build()
is API level 16. You probably have not set the target to v16 and/or downloaded the v16 android development kit, so that Eclipse does not know about that method and thus flags it as invalid.
Have a look at the documentation for Notification.Builder
Upvotes: 1