I am using this tutorial http://www.vogella.com/articles/AndroidNotifications/article.html , I want to build notification
// Prepare intent which is triggered if the // notification is selected
Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.addAction(R.drawable.icon, "Call", pIntent)
.addAction(R.drawable.icon, "More", pIntent)
.addAction(R.drawable.icon, "And more", pIntent).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
I have error in the line addAction
, eclipse says that the method addaction(ing, String pendingintent) is undefined for the type notification.builder
you have to use
android-support-v4.jar
file in yout project lib folder/lib/android-support-v4.jar
and add ityour ptoject---->properites (Alt+)-->Build Path-->Library-->add jar-->select
android-support-v4.jar
from lib folder --> okyour ptoject---->properites (Alt+)-->Build Path-->Order & Export--> select all--> ok.
using this your code run in <= 11 API LEVEL.
Edited: you are getting error because below method require MIN 11 API level
and below method require MIN API LEVEL 16:
so your solution is below use this way:
Make sure you have added
android-support-v4.jar
jar fileYou are using a bad version of the support library. AddAction has been introduced in r13 (maybe earlier).
You need to set your
sdkTargetVersion
in the<uses-sdk>
element ofAndroidManifest.xml
to be 16 or higher. TheaddAction(...)
method doesn't exist for older versions of Android.