Professional Documents
Culture Documents
Zmbufxuka 5 Document 5
Zmbufxuka 5 Document 5
XML Code:
<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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1;
b1 = (Button) findViewById(R.id.button);
createnotification();
b1.setOnClickListener(new View.OnClickListener() {
@Override
builder.setContentTitle(" Parth
Kunghatkar");
all ");
builder.setSmallIcon(R.drawable.ic_launcher_foreground);
NotificationManagerCompat m =
NotificationManagerCompat.from(MainActivity.this);
m.notify(0, builder.build());
});
NotificationChannel ch = new
ch.setDescription(description);
NotificationManager n =
getSystemService(NotificationManager.class);
n.createNotificationChannel(ch);