Notification Manager
Notification Manager
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/and
roid"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/cardview_default_radius
"
android:paddingLeft="@dimen/cardview_default_radius"
android:paddingRight="@dimen/cardview_default_radius"
android:paddingTop="@dimen/cardview_default_radius"
tools:context="MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification Example"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BWEC CSE "
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/ic_launcher_foreground"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification"
android:id="@+id/button"
android:layout_marginTop="62dp"
android:layout_below="@+id/imageButton"
android:layout_centerHorizontal="true" />
</RelativeLayout>
STRING.XML FILE
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="action_settings">Settings</string>
<string name="app_name">BwecCsse </string>
</resources>
NOTIFICATION.XML FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/r
es/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="400dp"
android:text="Hi, Your Detailed
notification view goes here...." />
</LinearLayout>
MANIFEST.XML FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com
/apk/res/android"
package="com.example.ex04" >
<uses-permission
android:name="android.permission.POST_NOT
IFICATIONS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_foreg
round"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name="com.example.ex04.MainActivi
ty"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action
android:name="android.intent.action.MAIN"
/>
<category
android:name="android.intent.category.LAU
NCHER" />
</intent-filter>
</activity>
<activity
android:name=".NotificationView"
android:label="Details of
notification"
android:parentActivityName=".MainActivity
">
<meta-data
android:name="android.support.PARENT_ACTI
VITY"
android:value=".MainActivity"/>
</activity>
</application>
</manifest>
NOTIFICATIONVIEW.JAVA FILE
package com.example.ex04;
import android.os.Bundle;
import android.app.Activity;
super.onCreate(savedInstanceState);
setContentView(R.layout.notification)
;
}
}
JAVA FILE
package com.example.ex04;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.*;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import
androidx.core.app.NotificationCompat;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 =
(Button)findViewById(R.id.button);
b1.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
addNotification();
}
});
}
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SER
VICE);
manager.notify(0,
builder.build());
}
}