Android Open Source - OpenGate Get Api






From Project

Back to project page OpenGate.

License

The source code is released under:

Apache License

If you think the Android project OpenGate 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.arquitetaweb.util;
/*  w w  w  . j  a v  a  2  s  . c o  m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class GetApi {
  private static final String ENCODING = "UTF-8";
  private String location = "";
  private String port = "80";

  public GetApi(String location) {
    this.location = location;
  }

  public String getFromApi(String action) {
    HttpClient client = new DefaultHttpClient();
    StringBuilder builder = new StringBuilder();
    HttpGet httpGet = new HttpGet("http://" + location + ":" + port + "/"
        + action);
    try {
      HttpResponse response = client.execute(httpGet);
      StatusLine statusLine = response.getStatusLine();
      int statusCode = statusLine.getStatusCode();
      if (statusCode == 200) {
        HttpEntity entity = response.getEntity();
        InputStream content = entity.getContent();
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(content, ENCODING));

        String line;
        while ((line = reader.readLine()) != null) {
          builder.append(line);
        }
      } else {
        Log.e("Error....", "Failed to download file");
      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return builder.toString();
  }
}




Java Source Code List

com.arquitetaweb.opengate.OpenGateIntentReceiver.java
com.arquitetaweb.opengate.OpenGateProvider.java
com.arquitetaweb.util.ApiController.java
com.arquitetaweb.util.GetApi.java
com.arquitetaweb.util.OpenGateController.java