getting code inside fragment and how to make notifications in fragments
Notifications in fragment
We can simply make notification as we make notification in activity or service .
You can even use features that are available with Android 4.1. If your app runs on devices with Android >=4.1 the new features will be used, if run on Android <4.1 the notification will be an simple old notification.
To create a simple Notification just do (see Android API Guide on Notifications):
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setContentIntent(pendingIntent); //Required on Gingerbread and below
You have to set at least smallIcon
, contentTitle
and contentText
. If you miss one the Notification will not show.
The Notification is added to the bar through the NotificationManager:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mId, mBuilder.build());
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.