An Easy Android App GET and POST Content From URL Example

December 18, 2016

** This post is a work in progress ** 

 

It took me a while (much longer than it should have) to be able to start playing around with getting and posting data to a url. I think part of the problem was that many of the tutorials out there try to add unecessary complication -- they'll add an interface where a user has to put in data, etc... and I'm just purely interested in the specific and lone action, without the extra fluff. 

 

So here is my little tutorial on this. For reference, my project is named: 'com.ctitch.birch'. Where relevant in the code below, you'll need to replace that.

 

1. Create a new project in android studio
2. Add "<uses-permission android:name="android.permission.INTERNET"/>" to your AndroidManifext.xml file.  That code should look like:

AndroidManifext.xml:




    

    
        
            
                

                
            
        
    

 

3. Add "compile 'com.android.volley:volley:1.0.0'" to the dependencies section of your build.gradle (Module:app) file.  It should look like:

build.gradle (Module:app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.androidtest.cedar"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.volley:volley:1.0.0'
}

 

More coming....