Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MAD Lab Assignment 5.

Name : Atharv A Nahar ; PRN : 12310613 ; Div : U; Roll No. : 42

XML Code:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Notify"

android:textColor="@color/black"

android:textColorHighlight="#2196F3"

android:textColorHint="#9C27B0"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.225" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA Code:-
package com.example.notification2;

import android.app.NotificationChannel;

import android.app.NotificationManager;

import android.os.Build;

import android.os.Bundle;

//import android.support.v4.app.NotificationCompat;

//import android.support.v4.app.NotificationManagerCompat;

//import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.NotificationCompat;

import androidx.core.app.NotificationManagerCompat;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button b1;

MAD Lab Assignment 5.

Name : Parth Kunghatkar; PRN : 12311034; Div : S; Roll No. : 2.

b1 = (Button) findViewById(R.id.button);

createnotification();

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

NotificationCompat.Builder builder = new


NotificationCompat.Builder(MainActivity.this, "My Notification");

builder.setContentTitle(" Parth

Kunghatkar");

builder.setContentText(" Hii,how are you

all ");

builder.setSmallIcon(R.drawable.ic_launcher_foreground);

NotificationManagerCompat m =

NotificationManagerCompat.from(MainActivity.this);

m.notify(0, builder.build());

});

private void createnotification() {

CharSequence name = "MAD Lab";

String description = "Assignment10";

int importance = NotificationManager.IMPORTANCE_DEFAULT;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

NotificationChannel ch = new

NotificationChannel("My Notification", name, importance);

ch.setDescription(description);

NotificationManager n =

getSystemService(NotificationManager.class);

n.createNotificationChannel(ch);

You might also like