Android Open Source - Android-Media-Library U P C R E S T Source






From Project

Back to project page Android-Media-Library.

License

The source code is released under:

Apache License

If you think the Android project Android-Media-Library 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 grevian.MediaLibrary;
/*from ww w  . ja va 2  s . com*/
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.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class UPCRESTSource {

  private static String url = "";

  private static String convertStreamToString(InputStream is) {
    /*
     * To convert the InputStream to String we use the
     * BufferedReader.readLine() method. We iterate until the BufferedReader
     * return null which means there's no more data to read. Each line will
     * appended to a StringBuilder and returned as String.
     */
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
      while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        is.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return sb.toString();
  }

  public static String getUPCText(String upc) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response;

    String text = "";
    try {
      response = httpclient.execute(httpget);
      // Examine the response status
      Log.i("Praeda", response.getStatusLine().toString());

      // Get hold of the response entity
      HttpEntity entity = response.getEntity();

      if (entity != null) {

        // A Simple JSON Response Read
        InputStream instream = entity.getContent();
        String result = convertStreamToString(instream);
        Log.i("Praeda", result);

        // A Simple JSONObject Creation
        JSONObject json = new JSONObject(result);
        Log.i("Praeda", "<jsonobject>\n" + json.toString()
            + "\n</jsonobject>");

        text = json.getString("result");
        
        Log.i("Praeda", "<jsonobject>\n" + json.toString()
            + "\n</jsonobject>");

        // Closing the input stream will trigger connection release
        instream.close();
      }

    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return text;
  }

}




Java Source Code List

grevian.MediaLibrary.ItemFoundActivity.java
grevian.MediaLibrary.LookupException.java
grevian.MediaLibrary.MediaContentProvider.java
grevian.MediaLibrary.MediaFactory.java
grevian.MediaLibrary.MediaLibrary.java
grevian.MediaLibrary.Media.java
grevian.MediaLibrary.TextSearchAdapter.java
grevian.MediaLibrary.UPCDataSource.java
grevian.MediaLibrary.UPCRESTSource.java
grevian.MediaLibrary.movieDetailsDatasource.java
org.xmlrpc.android.Base64Coder.java
org.xmlrpc.android.XMLRPCClient.java
org.xmlrpc.android.XMLRPCException.java
org.xmlrpc.android.XMLRPCFault.java
org.xmlrpc.android.XMLRPCSerializer.java