Java tutorial
package com.cybussolutions.wikki.afri_pay.Networking; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; import com.cybussolutions.wikki.afri_pay.LoginActivity; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.protocol.ClientContext; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * Created by Hamza Android on 10/14/2016. */ public class CheckAmount extends AsyncTask<String, String, String> { public String response; public HttpResponse responsebody; private String responseString; private ProgressDialog bar; private final Context context; String[] message; public CheckAmount(Context context) { this.context = context; } @Override protected void onPreExecute() { bar = new ProgressDialog(this.context); bar.setMessage("Loading..."); bar.setProgressStyle(ProgressDialog.STYLE_SPINNER); bar.setCancelable(false); //bar.show(); } @Override protected void onPostExecute(String re) { bar.dismiss(); } @Override protected String doInBackground(String... params) { LoginActivity.currentSession.authhttpClient = new DefaultHttpClient(); HttpContext ctx = new BasicHttpContext(); ctx.setAttribute(ClientContext.COOKIE_STORE, LoginActivity.currentSession.cookieStore); LoginActivity.currentSession.httppost = new HttpPost( LoginActivity.currentSession.base_url + "compliance/checkComplianceForTrans/"); List<BasicNameValuePair> nameValuePairs = new ArrayList<>(); String id = LoginActivity.currentSession.newProfile.getUserID(); String sending = LoginActivity.currentSession.newProfile.getCountryID(); nameValuePairs.add(new BasicNameValuePair("transAmount", params[0])); nameValuePairs.add(new BasicNameValuePair("localAmount", params[1])); nameValuePairs.add(new BasicNameValuePair("totalAmount", params[2])); nameValuePairs.add(new BasicNameValuePair("origenCountry", sending)); nameValuePairs.add(new BasicNameValuePair("destCountry", params[3])); nameValuePairs.add(new BasicNameValuePair("action", "send")); nameValuePairs.add(new BasicNameValuePair("originCYY", params[4])); nameValuePairs.add(new BasicNameValuePair("destCYY", params[5])); nameValuePairs.add(new BasicNameValuePair("customerID", id)); try { LoginActivity.currentSession.httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); responsebody = LoginActivity.currentSession.authhttpClient .execute(LoginActivity.currentSession.httppost, ctx); responseString = new BasicResponseHandler().handleResponse(responsebody); if (responseString.equals("1")) { return "1"; } else if (responseString.equals("nodocuments%")) { String complience; complience = "Documents Needed to Proceed this transaction"; return complience; } else if (responseString.equals("nodocuments%\n" + " Message: Docs Needed Please Go back to manage Documents to Upload missing documents. \n" + "Documents Need : Passport OR Driver License - Source of Funds - ")) { message = responseString.split("%"); } else { message = responseString.split("%"); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); return "Exception"; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return "Exception"; } if (responseString.contains("unable to allocate memory for pool") && responseString == null) { return "Exception"; } if (responseString.contains("logout")) { return "Exception"; } return message[1]; } }