In my application I need to display notification to the user. The following code snippet worked great by display the icon and content title in the Android device title bar.
Below code worked for me. Just a few corrections in the second snippet.
Intent resultIntent = new Intent(this, TestService.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, resultIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setContentIntent(pi)
.setAutoCancel(true)
.setContentTitle("title")
.setSmallIcon(R.drawable.ic_notif) //add a 24x24 image to the drawable folder
// and call it here
.setContentText("desc");
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0, builder.build());
I need to add .setTicker()
to the second code snippet to have text display in the Android device status bar