Android Notification
Android Notification
Android
Create an Android app that displays a simple notification when a button is clicked. The
notification should include a title, content, and a default icon.
Steps to Complete:
Code Snippet:
<Button
android:id="@+id/btnSimpleNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Notification" />
Code Snippet:
Code Snippet:
NotificationManagerCompat.from(this).notify(1, builder.build())
}
Code Snippet:
btnSimpleNotification.setOnClickListener {
showSimpleNotification()
}
Create a notification with an action button that redirects the user to the app when clicked.
Steps to Complete:
Code Snippet:
<Button
android:id="@+id/btnActionNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification with Action"
android:layout_marginTop="16dp" />
2. Set Up a PendingIntent:
o Define an intent to navigate the user back to the app when the action button is
clicked.
Code Snippet:
Code Snippet:
NotificationManagerCompat.from(this).notify(2, builder.build())
}
Code Snippet:
btnActionNotification.setOnClickListener {
showNotificationWithAction()
}