Aim: Create an android application to show the notification
Activity_Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ImageView android:id="@+id/imageView" android:layout_width="40dp" android:layout_height="40dp" android:layout_margin="8dp" android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/a1" />
<Button android:text="click"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:id="@+id/button" android:layout_marginTop="193dp" android:onClick="click" android:textStyle="bold" android:textSize="24sp"/>
</RelativeLayout>
MainActivity.java
package
com.example.demo.myapplication; import
android.app.NotificationManager; import
android.os.Bundle;
import android.support.v4.app.NotificationCompat; import
android.support.v7.app.AppCompatActivity; import
android.view.View;
public class MainActivity extends
AppCompatActivity { @Override
protected
void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}
public void click(View v)
{
NotificationCompat.Builder
nb=new NotificationCompat.Builder(this); nb.setContentTitle("notification Recieved");
nb.setContentText("Your notification is be prepared
for your android
exams"); nb.setSmallIcon(R.drawable.a1);
NotificationManager nm =(NotificationManager)getSystemService(NOTIFICATION_SERVICE); nm.notify(0,nb.build());
nb.setPriority(0);
}
}
Output
Comments
Post a Comment
If you have any doubts, Please let me know.