Notifications are an important part of on Applications, It's a Bridge Between App Developer and User. Here I will show you how to create Notifications in Android Studio. Here we are doing Offline notification which is generated by the Application. Offline Notification means notification which is generated By an App, without any Internet or third parties, firebase, google cloud.
Let's see the XML code for this. here we use a Button When we click the Button the NOtification will be displayed above Screen.
The Java Code by using Onclick Method.
Check out the Video on Youtube.
Subscribe
Hope this post is helpful, for a more useful post like and share with your friends, we also have Youtube channel for more details check out the video below, do like share and subscribe to our channel it will boost our energy and help to improve our work, Have Nice Day.
Let's see the XML code for this. here we use a Button When we click the Button the NOtification will be displayed above Screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.gcrt.notificationpro.MainActivity"> <Button
android:layout_marginTop="200dp"
android:text="Notify"
android:onClick="notify"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>
The Java Code by using Onclick Method.
ublic class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void notify(View view) { NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder notify = new NotificationCompat.Builder(this); notify.setSmallIcon(R.drawable.ic_camera_alt_black_24dp); notify.setContentText("Hi there"); notify.setContentTitle("Hello"); Intent intent = new Intent(MainActivity.this,MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0); notify.setContentIntent(pendingIntent); notify.setAutoCancel(true); manager.notify(1,notify.build()); } }
Subscribe
Hope this post is helpful, for a more useful post like and share with your friends, we also have Youtube channel for more details check out the video below, do like share and subscribe to our channel it will boost our energy and help to improve our work, Have Nice Day.
How to Create Notifications in Android Studio.
Reviewed by gcrt
on
August 17, 2018
Rating:

No comments: