HomeAndroidAndroid localhost connection using XAMPP / Django server

Android localhost connection using XAMPP / Django server

-

Sometimes we want to see how our app behaves locally before taking it live.This Tutorial is all about Android localhost connection using XAMPP server. Here, I’ll use my Newscrisp App which i’ve created recently for demonstration. Newscrisp uses Retrofit Library for Networking.

Initially download XAMPP server version according to your operating system in order to setup android localhost. In this tutorial, I will use Mac OS to demonstrate usage of Android Localhost connection.

[widget id=”text-3″]

You can also find the video tutorial on Android Localhost connection using Xampp and Django servers below:

[widget id=”text-3″]

Steps to implement Android Localhost connection using XAMPP Server:

Starting the services:


[widget id=”text-4″]
  1. Open XAMPP application and Start the application by clicking upon start in General Tab.                      
  2. Later, click START ALL services in Services tab in our Xampp Application.
  3. Then, click ENABLE in Network tab for local host forwarding.
  4. Now, click MOUNT to explore the XAMPP folders

After all this, we could find htdocs folder in our XAMPP folder in which we can place our required files in order to navigate from our localhost.

[wd_hustle id=”coderefer-email-optin-form”]

To test our Xampp server, let us try the following link (localhost:8080/dashboard/) and now the url should display the contents of index.html present in htdocs>dashboard folder.

Now, Create an internal folder, named json in htdocs folder to place our json file. Here i am placing a json file which I have prepared for the tutorial in my json folder.

Android Localhost Connection in Android Studio:

[widget id=”text-3″]

  1. Open Android studio to modify our project accordingly
  2. Update the BASE_URL in our code according to the android developer documentation as below 

3. Since I am using Retrofit library, in order to form complete url, i will create an interface as shown in the image below.

4. Now, run the emulator and we could see the articles written in json format are loading in our app from our localhost.

[adinserter block=”1″]

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

LATEST POSTS

SOLID Principles in Android with Kotlin Examples

Recently I had an interview experience where I went blank when the interviewer posed an Interesting Question - Explain SOLID Principles and how they are...

Building a Multi Module App in Android | Modularization in Android #1

Recently, I was in requirement for developing a Multi Module app in Android and I was going through this great lecture on it. This article...

Lambda function in Kotlin with Examples

Lambda function is powerful feature in any Programming language and Lambda function in Kotlin is no exception. In this article, we will look at how...

Higher Order Functions in Kotlin with examples

There are many advanced features in Kotlin which gives an edge for the user using this language over Java. One such feature is Higher Order...
Exit mobile version