Professional Documents
Culture Documents
Experiment - 03-MC
Experiment - 03-MC
Experiment - 03-MC
B1
EXPERIMENT - 03
● Notification Text: This attribute sets the main text that should be displayed with the
notification. This can include a short message or summary of the notification content.
3) Explain Channel creation and its attributes
In Android Studio, creating a channel for notification alerts refers to the process of setting up a
channel for delivering notifications to the user. Here are some common attributes of a
notification channel in Android Studio:
● ID: The ID of a notification channel is a unique identifier for the channel that is used to
identify and manage the channel within the app.
● Name: The name of a notification channel is the human-readable name of the channel
that is displayed to the user in the device's settings.
● Description: The description of a notification channel is a brief summary of the type of
notifications that will be delivered through the channel.
● Importance: The importance of a notification channel refers to the level of priority that
the notifications delivered through the channel will have. Android Studio provides four levels
of importance: High, Default, Low, and Min.
● Sound: The sound of a notification channel refers to the sound that will be played when a
notification is delivered through the channel.
● Vibration: The vibration of a notification channel refers to the vibration pattern that will
be used when a notification is delivered through the channel.
● LED Light: The LED light of a notification channel refers to the color and pattern of the
LED light that will be used when a notification is delivered through the channel.
Program Code:
MainActivity.java setContentView(R.layout.activity_main);
package com.example.message_notify_b1_17; Button
notifyButton=findViewById(R.id.button_notif
import android.app.NotificationChannel; y);
import android.app.NotificationManager; EditText
import android.os.Build; messageText=findViewById(R.id.my_messag
import android.os.Bundle; e);
import notifyButton.setOnClickListener(new
android.support.v4.app.NotificationCompat; View.OnClickListener() {
import @Override
android.support.v4.app.NotificationManagerC public void onClick(View v) {
ompat; String
import message=messageText.getText().toString();
android.support.v7.app.AppCompatActivity; NotificationCompat.Builder
import android.view.View; builder=new
import android.widget.Button; NotificationCompat.Builder(MainActivity.this
import android.widget.EditText; ,"My Notification")
public class MainActivity extends .setContentTitle("Alert")
AppCompatActivity { .setContentText(message)
@Override .setSmallIcon(R.drawable.baseline_notificatio
protected void onCreate(Bundle ns_active_24);
savedInstanceState) { NotificationManagerCompat
super.onCreate(savedInstanceState); managerCompat=
NAME : KRUNAL PATEL ROLL NO: 17 CLASS: TE_CMPN-
B1
NotificationManagerCompat.from(MainActivi
ty.this); android:src="@drawable/baseline_arrow_back_
managerCompat.notify(Integer.parseInt("1"), 24" />
builder.build()); <ImageView
if(Build.VERSION.SDK_INT>=Build.VERSI android:layout_width="wrap_content"
ON_CODES.O){ android:layout_height="wrap_content"
NotificationChannel channel=new
NotificationChannel("My android:src="@drawable/baseline_call_24" />
Notification","Notify",NotificationManager.I
MPORTANCE_DEFAULT); <ImageView
NotificationManager android:layout_width="wrap_content"
manager=getSystemService(NotificationMana android:layout_height="wrap_content"
ger.class);
android:src="@drawable/baseline_search_24" /
manager.createNotificationChannel(channel); >
} </LinearLayout>
} <LinearLayout
}); android:layout_width="wrap_content"
}} android:layout_height="wrap_content"
android:layout_gravity="center"
Activity_main.xml android:layout_marginTop="10dp">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout <TextView
xmlns:android="http://schemas.android.com/apk android:layout_width="wrap_content"
/res/android" android:layout_height="wrap_content"
android:text="To"
xmlns:tools="http://schemas.android.com/tools" android:textColor="@color/black"
android:layout_width="match_parent" android:layout_marginRight="25px"
android:layout_height="match_parent" android:textSize="25dp" />
android:orientation="vertical">
<ImageView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:layout_marginLeft="330dp"
android:layout_marginLeft="80dp"
android:text="New Message" android:src="@drawable/baseline_person_add_
android:textSize="40dp" 24" />
android:layout_marginTop="10dp" </LinearLayout>
android:textColor="@color/black"/>
<LinearLayout
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_gravity="center"
android:layout_marginTop="500dp">
android:layout_marginBottom="0dp">
<ImageView
<ImageView
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginRight="325dp"
NAME : KRUNAL PATEL ROLL NO: 17 CLASS: TE_CMPN-
B1
android:layout_height="wrap_content"
android:src="@drawable/baseline_add_circle_o android:layout_margin="10dp"
utline_24" />
<EditText android:src="@drawable/baseline_emoji_emoti
android:id="@+id/my_message" ons_24" />
android:layout_width="wrap_content"
android:layout_height="wrap_content" <Button
android:hint="Type a Message" android:id="@+id/button_notify"
android:textAlignment="center" android:layout_width="wrap_content"
android:textSize="20dp" android:layout_height="wrap_content"
android:width="160dp" android:background="@color/black"
android:text="Send"
tools:ignore="TouchTargetSizeCheck" /> android:textColor="@color/white" />
</LinearLayout>
<ImageView
</LinearLayout>
android:layout_width="wrap_content"
OUTPUT:
Conclusion : Thus we have successfully created a notification alert application that gives an alert message in
the notification panel . In the MainActivity.java We have used the NotificationCompat.Builder class of java that
provides attributes and customizations to the notification alert also we have used the Notification Manager.class
NAME : KRUNAL PATEL ROLL NO: 17 CLASS: TE_CMPN-
B1
for setting the Importance of the notification alert i.e. whether the given notification alert needs an importance of
HIGH MEDIUM or LOW . While using Activity_main.xml has been used to give the basic layout to our
notification application and also set up the notification icon for the alert we are getting in the notification panel.
We have understood the working of these classes and how to implement them in different ways in our application.