0% found this document useful (0 votes)
25 views5 pages

Notification Manager and Push Notification

Mad

Uploaded by

atharv.saste232
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

Notification Manager and Push Notification

Mad

Uploaded by

atharv.saste232
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Android Notifications

Notification Manager and Push Notification

 Notifications provide short, timely information about events in your app while
it isn't in use.

 It allows developers to create and display notifications to users on behalf of


their apps.

 The Notification Manager API provides the ability to create notifications and
control their behavior.

 Notifications can be displayed in the notification shade, on the lock screen, and
in the status bar.
•Notifications can be generated in Android for a variety of reasons. Here are some
common scenarios where you might generate a notification:

•New message or email: You can generate a notification when the user receives a new
message or email in your app.

•Reminder or alarm: You can generate a notification when the user has a scheduled reminder
or alarm in your app.

•Event or appointment: You can generate a notification when the user has an upcoming event
or appointment in your app.

•Download or upload completion: You can generate a notification when a download or


upload is completed in your app.

•Progress updates: You can generate a notification to show progress updates for a long-
running operation in your app.

•App updates: You can generate a notification to inform the user about updates to your app.

•Low battery or data usage warning: You can generate a notification to warn the user about
low battery or high data usage in your app.
Developers can use the NotificationManager class to create and manage notifications within
their apps.
To create a notification, developers first need to create a NotificationCompat.Builder object,
which is a helper class that provides a convenient way to construct notifications with various
properties, such as title, text, icon, and actions.

NotificationCompat.Builder builder= new


NotificationCompat.Builder(MainActivity.this, "my notification")
builder.setContentTitle("This is MAD Lab");
builder.setAutoCancel(true);
builder.setContentText("My Notification");
builder.setSmallIcon(R.drawable.ic_launcher_background);
NotificationManagerCompat manager
=NotificationManagerCompat.from(MainActivity.this);
manager.notify(0,builder.build( ));
Creating a notification channel
• Now to deliver notifications on android version 8.0 and above versions, we need to create a
notification channel.
• Before you can deliver the notification on Android 8.0 and above versions, you must register
your app’s notification channel with the system by passing an instance
of NotificationChannel to createNotificationChannel( ).

private void createnotificationchannel( )


{
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
{
CharSequence name="MAD lab B3"; //charsequence is read only
String description="Lab Assignment of MAD";
int importance= NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel=new NotificationChannel("Notifi_app",name,importance);
channel.setDescription(description);
NotificationManager notificationManager=getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}

You might also like