How to Create Notifications in Android Studio.

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.



<?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());


    }

}









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.

How to Create Notifications in Android Studio. How to Create Notifications in Android Studio. Reviewed by gcrt on August 17, 2018 Rating: 5

No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.