Skip to content

Just a simple program that can send a HTTP request by clicking the "check" button. Programmed to connect through localhost. Check readme.md for more info.

Notifications You must be signed in to change notification settings

MaxKei/AndroidStudio-HTTPClient

Repository files navigation

AndroidStudio-HTTPClient

A Simple HTTTP Request client, that's requesting a string from a nodejs webserver.
Tux, the Linux mascot

Libraries:

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

Required configuration:

In MainActivity.java:

Change http://10.0.2.2:3000/ to your IP-Address, unless your webserver is localhost.
Rememberlocalhost:3000 -> Android recognize localhost as: 10.0.2.2
Check/edit ID for button: Button contactServerButton = findViewById(R.id.button1);

In AndroidManifest.xml

add android:usesCleartextTraffic="true"
add <uses-permission android:name="android.permission.INTERNET" />

In activity_main.xml

Check/edit ID button: android:id="@+id/button1"

File location: MainActivity.java: AndroidStudio-HTTPClient/app/src/main/java/com/example/clienttonodejs/MainActivity.java
File location: AndroidManifest.xml: AndroidStudio-HTTPClient/app/src/main/AndroidManifest.xml
File location: activity_main.xml: AndroidStudio-HTTPClient/app/src/main/res/layout/activity_main.xml


Code is adapted from: Android AsyncTask HTTP GET request Tutorial and Minimal clien-server example for Android and Node.js

About

Just a simple program that can send a HTTP request by clicking the "check" button. Programmed to connect through localhost. Check readme.md for more info.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published