Verifying Username availability via an App: How Java RESTful Comes Handy

Well, how much time do you spend in choosing a strong username for joining a website, an online group or for signing up to one of your favorite apps? I’m sure most of you would answer a couple of seconds. As per a globally conducted research, it has been found that investing a few extra seconds on choosing your username can turn to be a wise decision for building your unique profile. This post of mine is dedicated to all those developers who intend to create a username availability check Android application using the Java RESTful Webservice. So, hop onto all the details that have been mentioned here. 

Image 1

RESTful Webservice- What is it exactly?

However, for availability of this platform, you can avail Android Developer for Hire but be aware of that fact that the text REST in RESTful Webservices stands for Representational State Transfer and was first introduced by Roy Fielding in the year 2000. As a finest architectural style, REST comprises of resources that are handled using GET, POST, PUT and DELETE operations which are absolutely similar to Read, Create, Update and Delete operations. Every request from client to server within REST is unique, independent and comprises of details that are necessary for understanding the same effectively. In RESTful webservice, all communications are implemented via representations including JSON, XML.

Step 1- Create/download RESTful webservice

As the very first step, you can either choose to create the RESTful webservice or can download the same from the internet, followed by deploying it in your local application server.

Step 2-Create a new Android Application Project

For this, go to File-> New-> Android Application Project and name the project as: UserNameCheck.Next, enter the package name as ‘com.mrgguru.example’.

After this, choose suitable values for fields viz: Minimum Required SDK, Target SDK and Compile with. If you’re confused about choosing values for these fields, go through useful online blogs that aid you in selecting the correct values. After having made the choices, click on the “Next” button, followed by clicking the “Finish” button to create the Android application project. 

Step 3- Equip the project with library

Image 3

Now, add genuine third-party library into the newly created Android application project’s’lib’ folder. If you don’t have one, you can always choose to download it from the internet.

Step 4- Design the Android app’s screen

The project UserNameCheck has the following components:

  • Edittext field– this is used for entering the username
  • Button– this is used for sending username to Server
  • TextView/ImageView– this is used for displaying the entered username’s availability status i.e. whether the user can proceed ahead with the entered username or is he/she required to insert a brand new username. Now, create a layout XML under the /res/layout folder as explained below:

<?xmlversion=”1.0″encoding=”utf-8″?>

<RelativeLayoutxmlns:android=”http://schemas.android.com/apk/res/android

    android:id=”@+id/RelativeLayout01″

    android:layout_width=”fill_parent”

    android:layout_height=”fill_parent”>

    <ImageView

        android:id=”@+id/statusImg”

        android:layout_width=”wrap_content”

        android:layout_height=”wrap_content”

        android:layout_centerHorizontal=”true”android:layout_marginTop=”10dp”/>

     <TextView

        android:id=”@+id/unameTextView”

        android:layout_width=”match_parent”

        android:layout_height=”wrap_content”

        android:layout_below=”@+id/statusImg”

        android:layout_centerHorizontal=”true”

        android:layout_marginBottom=”15dp”

        android:gravity=”center_horizontal”

        android:text=”Result will appear here”

        android:textAppearance=”?android:attr/textAppearanceMedium”/>

 Similarly, create for Edittext field and Button also.

 Step 5- Create the Utility.java class

Image 4

After having done with the app layout designing phase, go ahead with creating the Utility.Java class under the chosen package. This class would include all the utility methods that would further be used in other Activity classes within the Android application. The coding that’s involved here is mentioned below:

package com.mrgguru.example;

/**

 * Class which has Utility methods

 *

 */

publicclassUtility {

    /**

     * Checks for Null String object

     *

     * @param txt

     * @return true for not null and false for null String object

     */

    publicstaticbooleanisNotNull(String txt){

        returntxt!=null&& txt.trim().length()>0? true: false;

    }

}

Step 6- Using UserNameCheck.java class

UserNameCheck.java is the application Home screen class that allows the users to enter a username, followed by checking whether the same is available for selection or not. Here, you need to ensure that the IP address in the AsyncHttp Get method has been changed to the IP address of your computer system. Since the UserNameCheck.java class is well commented, it becomes quite easy for you to make any changes to the code.

Step 7- As the last step, test the code by simply running the created Android application using an emulator/device by following the steps:

Right click on the Android Application Project-> Run as-> Android Application-> Choose emulator or the preferred device.

Conclusion

So, with that it’s a wrap on this post that covers a definitive guideline on using Java RESTFul webservice for creating an Android application that checks the availability of a particular username. Hope you’d have found the post interesting and useful enough for reference during your next Android app development venture that involves creation of an app that checks a username’s availability for selection. 

Author Bio:

Juana StevesJuana Steves is a technical writer associated with Xicom Technologies – a leading Android Application Development Company. You can also opt to avail Android Developer for Hire, in case you are looking forward for the same.

Leave a Reply