user2251607
user2251607

Reputation: 19

How to notification

There is the code:

Notification notification = new Notification.Builder(this).setContentTitle("New mail from").setContentText("Text")
.setSmallIcon(android.R.drawable.btn_plus).setLargeIcon(Bitmap.createBitmap(20, 20, null))
.build();

The error reads:

The method build() is undefined for the type Notification.Builde.

I get this code from Google example. What I am doing wrong?

Upvotes: 0

Views: 66

Answers (2)

pankaj tirole
pankaj tirole

Reputation: 1

If you are targeting your os after Honeycomb then you will need to implement NotificationCompat.Builder class.

Try this:

           NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

           Notification notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(appname).setWhen(when)
                .setAutoCancel(true).setContentTitle(appname)
                .setContentText(message).build();

           notificationManager.notify(0, notification);

Upvotes: 0

Aun
Aun

Reputation: 1923

it required minimum API level 16 you can increase the minimum API level in AndroidManifest.xml file (incase you are targeting your app only for devices above that)

or you can use NotificationCompat.Builder which comes as support library

Upvotes: 1

Related Questions