2

can any one give me the complete code for Http get and post request for android like this https://wowjava.wordpress.com/2011/01/16/login-application-for-android/ . Please help i wanted to make login check from server.so i want to make a post request please help me. as a new android developer i can not resolving this issue.So please help me.

build.gradle (module:app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.systechdigital.realtimetrackingandmonitoring"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
}

My MainActivity:

package com.systechdigital.realtimetrackingandmonitoring;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.NameValuePair;



public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    ImageView icon_image;
    ImageView login_image;
    EditText username_editText;
    EditText password_editText;
    Button remember_me_button;
    Button forget_password_button;
    Button sign_up_button;



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

        icon_image =(ImageView)findViewById(R.id.icon_imageView_id);
        login_image=(ImageView)findViewById(R.id.imageView_login_id);
        username_editText=(EditText)findViewById(R.id.user_login_email_id);
        password_editText=(EditText)findViewById(R.id.login_password);
        remember_me_button=(Button)findViewById(R.id.remember_me_id);
        forget_password_button=(Button)findViewById(R.id.forget_password_id);
        sign_up_button=(Button)findViewById(R.id.sign_up_button_id);


        login_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent mainToSignUpIntent=new Intent(getApplicationContext(),SignUPActivity.class);
                startActivity(mainToSignUpIntent);

                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();

            }
        });

    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }



    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}
im07
  • 386
  • 2
  • 12

1 Answers1

0
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();

This is wrong declaration, instead of NameValuePair you are suppose to be giving datatype of arraylist containing element such as

ArrayList<String> postParameters = new ArrayList<String>();
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
brjichkar
  • 33
  • 7