Skip to content

Instantly share code, notes, and snippets.

@fahidmohammad
Forked from azec-pdx/onCreate.java
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save fahidmohammad/8cb46d24a198fa9cd116 to your computer and use it in GitHub Desktop.

Select an option

Save fahidmohammad/8cb46d24a198fa9cd116 to your computer and use it in GitHub Desktop.

Revisions

  1. @azec-pdx azec-pdx created this gist Jan 15, 2015.
    58 changes: 58 additions & 0 deletions onCreate.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
    .permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.activity_main);
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
    "http://www.cheesejedi.com/rest_services/get_big_cheese.php?puzzle=");
    TextView textView = (TextView) findViewById(R.id.textView1);
    try {

    HttpResponse response = httpclient.execute(httppost);
    String jsonResult = inputStreamToString(
    response.getEntity().getContent()).toString();

    JSONArray jsonArray = new JSONArray(jsonResult);

    for (int i = 0; i < jsonArray.length(); i++) {
    textView.append("id: "
    + jsonArray.getJSONObject(i).getString("id").toString()
    + "\n");
    textView.append("level: "
    + jsonArray.getJSONObject(i).getString("level")
    .toString() + "\n");
    textView.append("time_in_secs: "
    + jsonArray.getJSONObject(i).getString("time_in_secs")
    .toString() + "\n");
    textView.append("par: "
    + jsonArray.getJSONObject(i).getString("par")
    .toString() + "\n");
    textView.append("initials: "
    + jsonArray.getJSONObject(i).getString("initials")
    .toString() + "\n");
    textView.append("quote: "
    + jsonArray.getJSONObject(i).getString("quote")
    .toString() + "\n");
    textView.append("time_stamp: "
    + jsonArray.getJSONObject(i).getString("time_stamp")
    .toString() + "\n");
    textView.append("-------------------------------------------------"
    + "\n");

    }

    // textView.setText(jsonResult);

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

    }