Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.berko.tictactoe;
- import java.io.IOException;
- 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.apache.http.util.EntityUtils;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.app.Activity;
- import android.content.Context;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.view.Menu;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- static Context context;
- HttpClient client;
- TextView t;
- JSONObject json;
- final static String URL = "http://nirberko.info/android/index.php";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- context = this;
- t = (TextView)findViewById(R.id.textView1);
- client = new DefaultHttpClient();
- new Read().execute("bla");
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- public JSONObject lastTweet(String function) throws ClientProtocolException, IOException, JSONException {
- StringBuilder url = new StringBuilder(URL);
- HttpGet get = new HttpGet(url.toString());
- HttpClient httpclient = new DefaultHttpClient();
- HttpResponse response = httpclient.execute(get);
- int status = response.getStatusLine().getStatusCode();
- if (status == 200) {
- HttpEntity e = response.getEntity();
- String data = EntityUtils.toString(e);
- JSONArray timeline = new JSONArray(data);
- JSONObject last = timeline.getJSONObject(0);
- t.setText("good");
- return null;
- } else {
- t.setText("error");
- return null;
- }
- }
- public class Read extends AsyncTask<String, Integer, String> {
- @Override
- protected String doInBackground(String... arg0) {
- // TODO Auto-generated method stub
- try {
- json = lastTweet("bla");
- } 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 null;
- }
- @Override
- protected void onPostExecute(String result) {
- // TODO Auto-generated method stub
- super.onPostExecute(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement