0% found this document useful (0 votes)
46 views7 pages

Android Notification Manager Example

Uploaded by

fakersspot.1412
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)
46 views7 pages

Android Notification Manager Example

Uploaded by

fakersspot.1412
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

XML FILE

<RelativeLayout
xmlns:android="[Link]
roid"
xmlns:tools="[Link]
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>

[Link] FILE
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="action_settings">Settings</string>
<string name="app_name">BwecCsse </string>
</resources>

[Link] FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
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>

[Link] FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="[Link]
/apk/res/android"
package="[Link].ex04" >

<uses-permission
android:name="[Link].POST_NOT
IFICATIONS" />
<application
android:allowBackup="true"

android:icon="@drawable/ic_launcher_foreg
round"
android:label="@string/app_name"

android:theme="@style/[Link]" >

<activity

android:name="[Link]
ty"

android:label="@string/app_name"
android:exported="true">

<intent-filter>
<action
android:name="[Link]"
/>
<category
android:name="[Link]
NCHER" />
</intent-filter>

</activity>

<activity
android:name=".NotificationView"
android:label="Details of
notification"

android:parentActivityName=".MainActivity
">
<meta-data

android:name="[Link].PARENT_ACTI
VITY"

android:value=".MainActivity"/>
</activity>

</application>
</manifest>
[Link] FILE
package [Link].ex04;

import [Link];
import [Link];

public class NotificationView extends


Activity{
@Override
public void onCreate(Bundle
savedInstanceState){

[Link](savedInstanceState);

setContentView([Link])
;
}
}

JAVA FILE
package [Link].ex04;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];

import
[Link];

public class MainActivity extends


Activity {
Button b1;
@Override
protected void onCreate(Bundle
savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

b1 =
(Button)findViewById([Link]);
[Link](new
[Link]() {
@Override
public void onClick(View v) {
addNotification();
}
});
}

private void addNotification() {


[Link]
builder =
new
[Link](this)
.setSmallIcon(R.d
rawable.ic_launcher_foreground)
.setContentTitle(
"Notifications Example")
.setContentText("
This is a test notification");

Intent notificationIntent = new


Intent(this, [Link]);
PendingIntent contentIntent =
[Link](this, 0,
notificationIntent,

PendingIntent.FLAG_UPDATE_CURRENT);

[Link](contentIntent);

// Add as notification
NotificationManager manager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SER
VICE);
[Link](0,
[Link]());
}
}

You might also like