Display Notification Text In Status Bar - Android
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. var no
Solution 1:
I need to add .setTicker()
to the second code snippet to have text display in the Android device status bar
Solution 2:
Below code worked for me. Just a few corrections in the second snippet.
IntentresultIntent=newIntent(this, TestService.class);
PendingIntentpi= PendingIntent.getActivity(this, 0, resultIntent, 0);
NotificationCompat.Builderbuilder=newNotificationCompat.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");
NotificationManagernm= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0, builder.build());
Post a Comment for "Display Notification Text In Status Bar - Android"