Android Open Source - pawang-ujan Service Handler






From Project

Back to project page pawang-ujan.

License

The source code is released under:

Apache License

If you think the Android project pawang-ujan listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.salatiga.code;
/*from  ww w.j a  v a2 s .  c  o  m*/
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * Class untuk utility untuk mangambil konten di web
 * @author Hendro Steven Tampake
 * @version 1.0
 *
 */
public class ServiceHandler {
  static String response = null;
  public final static int GET = 1;
  public final static int POST = 2;

  public ServiceHandler() {

  }

  /**
   * Making service call
   * 
   * @url - url to make request
   * @method - http request method
   * */
  public String makeServiceCall(String url, int method) {
    return this.makeServiceCall(url, method, null);
  }

  /**
   * Making service call
   * 
   * @url - url to make request
   * @method - http request method
   * @params - http request params
   * */
  public String makeServiceCall(String url, int method,
      List<NameValuePair> params) {
    try {
      // http client
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpEntity httpEntity = null;
      HttpResponse httpResponse = null;

      // Checking http request method type
      if (method == POST) {
        HttpPost httpPost = new HttpPost(url);
        // adding post params
        if (params != null) {
          httpPost.setEntity(new UrlEncodedFormEntity(params));
        }

        httpResponse = httpClient.execute(httpPost);

      } else if (method == GET) {
        // appending params to url
        if (params != null) {
          String paramString = URLEncodedUtils.format(params, "utf-8");
          url += "?" + paramString;
        }
        HttpGet httpGet = new HttpGet(url);

        httpResponse = httpClient.execute(httpGet);

      }
      httpEntity = httpResponse.getEntity();
      response = EntityUtils.toString(httpEntity);

    } catch (Exception e) {
      
    } 

    return response;

  }
}




Java Source Code List

android.UnusedStub.java
com.salatiga.code.CuacaFragment.java
com.salatiga.code.Cuaca.java
com.salatiga.code.GPSTracker.java
com.salatiga.code.GempaFragment.java
com.salatiga.code.GempaListAdapter.java
com.salatiga.code.GempaXmlParser.java
com.salatiga.code.Gempa.java
com.salatiga.code.InfoActivity.java
com.salatiga.code.MainActivity.java
com.salatiga.code.MapActivity.java
com.salatiga.code.ServiceHandler.java
com.salatiga.code.SettingsActivity.java
com.salatiga.code.adapter.TabsPagerAdapter.java