Creating Notification in Android

Here is a code for creating notification for your application. Copy the below code to your project, 

private void createNotification(String tickerText, String contentTitle,
String contentText, int notiIcon) {
String notiservice = Context.NOTIFICATION_SERVICE;
NotificationManager notimanager = (NotificationManager) getSystemService(notiservice);

int icon = notiIcon;
CharSequence tickerText = tickerText;
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = contentTitle;
CharSequence contentText = contentText;

Intent notiIntent = new Intent(this, Options.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0,
notiIntent, 0);

Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText,

final int ID = 1;
notimanager.notify(ID, notification);

And then call it with following parameters,
createNotification("My Notification", "Jimmanz", "Notification Started",

Popular posts from this blog

Async Task in Android

Shake effect in Android

Example For ListView Using BaseAdapter