Posts

Showing posts from June, 2021

How to create Pop-Up Dialog Animation in App | Android App Development | Java

Image
 In this post, you will learn how to create Pop-Up animation for Dialog Box in your Android Application. A dialog is a small window that prompts the user to make decision or enter additional information. A dialog is normally used for modal events that require users to take an action before they can proceed. Implementation: First, create a new Android Resource Directory of type 'anim'. In it create two anim files 'scale_up.xml' and 'scale_down.xml'. These files will contain the code for our dialog animation. In the scale_up.xml file, add the following code: And in the scale_down.xml file, add the following code: Create a new style and add these two xml files to it. Now add a button in the activity_main.xml file which will instantiate the pop-up dialog.   Now create a new layout file which will contain the design layout of the dialog box .Add the following code to it.  Finally, in the MainActivity.java class, setup the dialog box  like so... Output :

How to check internet availability in app | Android App Development | Java

 In this post, you will learn how to check the internet availability access in your application. Checking the internet access is important when working with API's, fetching or uploading data from servers etc... Implementation: First, in the activity_main.xml file, add the following code: Then, create a new activity (NewActivity), and in its xml file (activity_new.xml), add the following code: Now in the MainActivity.java file, add the onClickListener to the button to navigate to the NewActivity. To do this, add the following code: After this, create a new Java class to check the network state. In this class (CheckNetwork.java), add the following code: Now, in the NewActivity.java file, add the following code: Finally, add the Internet and Access Network State permissions in the AndroidManifest.xml file And that's it...Now try running your app. To learn more about reading the Network States in Android, refer this : https://developer.android.com/training/basics/network-ops/read

How to play Audio on Button Click in app | Android App Development | Java

 In this post, you will learn how to play audio on button click feature in your Android App. We will be using the MediaPlayer to implement this functionality. MediaPlayer class can be used to control playback of audio/video files and streams. MediaPlayer is not thread-safe. Creation of and all access to player instances should be on the same thread. If registering  c allbacks, the thread must have a Looper. Implementation: First, in the activity_main.xml file, add the following code: Then, create a new Android Resources Directory of type ' raw ' and add the audio sounds of your choice in it. Then in the MainActivity.java file, add the following code: Output: