Android Studio Examples

100+ tutorials, source code, and examples to help you develop creative and technical skills.

Easiest and Simple way to make GET and POST request in Android Studio

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.learnoset.myapplication">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

gradle.build

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.learnoset.myapplication"
        minSdkVersion 19
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    testImplementation 'junit:junit:'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.github.learnoset:networking:5.21.2'
}

gradle.build (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

MainActivity.java

package com.learnoset.myapplication;

import android.content.Context;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.learnoset.networking.LearnosetNetRequest;
import com.learnoset.networking.NetResponseListener;
import com.learnoset.networking.RequestMethod;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // initialize Learnoset Network Library
        LearnosetNetRequest.init("url_here", this);

        // Make POST Request
        sendPOSTRequest();

        // make GET request
        sendGETRequest();
    }

    private void sendPOSTRequest() {

        // creating object
        LearnosetNetRequest request = new LearnosetNetRequest(this, RequestMethod.POST);

        // adding post parameters
        request.addParam("param_1_key", "param_1_value");
        request.addParam("param_2_key", "param_2_value");
        request.addParam("param_3_key", "param_3_value");
        request.addParam("param_4_key", "param_4_value");
        request.addParam("param_5_key", "param_5_value");

        // execute request
        request.execute(true, 10, new NetResponseListener() {
            @Override
            public void onRequestSuccess(String response, Context context, int resultCode) {

                // handle response here
            }

            @Override
            public void onRequestFailed(String errorMessage, Context context, int resultCode) {

                // handle errors here
            }
        });

    }

    private void sendGETRequest() {

        // creating object
        LearnosetNetRequest request = new LearnosetNetRequest(this, RequestMethod.GET);

        // adding post parameters
        request.addParam("param_1_key", "param_1_value");
        request.addParam("param_2_key", "param_2_value");

        // execute request
        request.execute(true, 11, new NetResponseListener() {
            @Override
            public void onRequestSuccess(String response, Context context, int resultCode) {

                // handle response here
            }

            @Override
            public void onRequestFailed(String errorMessage, Context context, int resultCode) {

                // handle errors here
            }
        });

    }

}

Projects with Source Code + Video Tutorials

You can download our Java and Android Studio Projects with Source Code and Video Tutorials.

Login-&-Register-Screen-UI-Design---02
Login & Register Screen UI Design - 02
Login-&-Register-Screen-UI-Design---01
Login & Register Screen UI Design - 01
Simple-Music-Player-App-(Version-2)-for-Android-(Offline-Version)
Simple Music Player App (Version 2) for Android (Offline Version)

If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com

Follow us to learn Coding and get in touch with new Technologies.