I am creating a small app for android for notification.
But it gives an Error in Notification class error (API level supported for 11 or 16).
Then I tried using NotificationCompat class but it shows resources can not be resolved to a type while I import package import android.support.v4.app.NotificationCompat.Builder;
In other words, if I use Notification class then it give API level Error, and if I use NotificationCompat then it gives that resource error. How can I resolve both these errors?
public void createNotification(View view) {
// Prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Context context=new Context();
// Build notification
// Actions are just fake
NotificationCompat.Builder noti = new NotificationCompat.Builder(this)
.setContentTitle("New mail from " + "star.ankit90@gmail.com")
.setContentText("Subject").setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.addAction(R.drawable.ic_launcher, "Call", pIntent)
.addAction(R.drawable.ic_launcher, "More", pIntent)
.addAction(R.drawable.ic_launcher, "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);
}