0% found this document useful (0 votes)
10 views4 pages

Notifications

The document is an assignment on Android app development submitted by Syed Mazhar Hussain Shah, focusing on various types of notifications including expandable, inbox, call, and messaging notifications. Each notification type is explained with code snippets demonstrating how to implement them in an Android application. The assignment emphasizes the importance of notifications for user engagement and timely updates.

Uploaded by

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

Notifications

The document is an assignment on Android app development submitted by Syed Mazhar Hussain Shah, focusing on various types of notifications including expandable, inbox, call, and messaging notifications. Each notification type is explained with code snippets demonstrating how to implement them in an Android application. The assignment emphasizes the importance of notifications for user engagement and timely updates.

Uploaded by

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

Dr. A. Q.

Khan Institute of
Computer Sciences and
Information Technology Kahuta
Android App Development
ASSIGNMENT

Submitted by:
Syed Mazhar Hussain Shah
(222201011)
BSCS-6

Submitted to: Sir Umar

• Introduction This application demonstrates various types of


notifications in Android, such as expandable notifications, inbox
notifications, call notifications, and messaging notifications. These
notifications are crucial for alerting users to important events or
updates even when they are not using the app.
• Code Explanation :
• Expandable Notification:
• Explanation: Expandable notifications allow users to expand the
notification to view more content, which is useful for long texts ,this
code creates an expandable notification using BigTextStyle to display a
longer message when expanded.
• Code Snippet: NotificationCompat.Builder builder = new
NotificationCompat.Builder(this,
CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_dialog_info) .setCont
entTitle("Expandable Notification") .setContentText("Swipe down to
expand") .setStyle(new
NotificationCompat.BigTextStyle() .bigText("This is an example of an
expandable notification. You can show more details when the user
expands it. It's very useful for long messages or
descriptions.")) .setPriority(NotificationCompat.PRIORITY_HIGH); Output

Inbox Notification:
Explanation: Inbox-style notifications display multiple messages within a
single notificationThe InboxStyle allows displaying multiple lines within a
notification, useful for inbox or chat-like notifications..
Code Snippet: NotificationCompat.InboxStyle inboxStyle = new
NotificationCompat.InboxStyle() .setBigContentTitle("Inbox
Messages") .addLine("Ali: Hello!") .addLine("Sara: Assignment
done?") .addLine("John: Meeting at 3 PM") .addLine("Hina: Call me
ASAP") .addLine("Zain: Check email");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_dialog_email) .setContentT
itle("Inbox Notification") .setContentText("You have 5 new
messages") .setStyle(inboxStyle) .setPriority(NotificationCompat.PRIORITY_D
EFAULT);

Output
Call Notification:
Explanation: Call notifications allow the user to either accept or decline an
incoming call from the notification itself.This code implements a call
notification with actions to accept or decline the call.
Code Snippet: Intent acceptIntent = new Intent(this, MainActivity.class); //
Dummy intent PendingIntent acceptPendingIntent =
PendingIntent.getActivity(this, 0, acceptIntent,
PendingIntent.FLAG_IMMUTABLE);
Intent declineIntent = new Intent(this, MainActivity.class); PendingIntent
declinePendingIntent = PendingIntent.getActivity(this, 1, declineIntent,
PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
CHANNEL_ID) .setSmallIcon(android.R.drawable.sym_call_incoming) .setCont
entTitle("Incoming Call") .setContentText("Zain is
calling...") .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(Noti
ficationCompat.CATEGORY_CALL) .addAction(android.R.drawable.sym_action_
call, "Accept",
acceptPendingIntent) .addAction(android.R.drawable.ic_menu_close_clear_ca
ncel, "Decline",
declinePendingIntent) .setAutoCancel(true) .setFullScreenIntent(acceptPendi
ngIntent, true);

Output

Message Notification:
Explanation: Message notifications use the MessagingStyle to display a
conversation with multiple messages The MessagingStyle creates a message
thread, useful for chat-style notifications..

Code Snippet: Person sender = new


Person.Builder() .setName("Ali") .build();
NotificationCompat.MessagingStyle.Message message1 = new
NotificationCompat.MessagingStyle.Message("Hey! Did you check the
report?", System.currentTimeMillis(), sender);
NotificationCompat.MessagingStyle messagingStyle = new
NotificationCompat.MessagingStyle(sender) .addMessage(message1);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
CHANNEL_ID) .setSmallIcon(android.R.drawable.sym_action_chat) .setStyle(
messagingStyle) .setContentTitle("Ali") .setContentText("New
message") .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(Noti
ficationCompat.CATEGORY_MESSAGE);

Output

Winrar file attached

You might also like