Android Open Source - Game-of-thrones-trivia Request Web Service






From Project

Back to project page Game-of-thrones-trivia.

License

The source code is released under:

MIT License

If you think the Android project Game-of-thrones-trivia 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.GameOfThrones.Trivia.data;
//w w w.  j  a v a 2s.  c o  m
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
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.os.AsyncTask;

public class RequestWebService extends AsyncTask<String, Integer, String> {
  @Override
  protected String doInBackground(String... uri) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse response;
    String responseString = null;
    try {
      response = httpClient.execute(new HttpGet(uri[0]));
      StatusLine statusLine = response.getStatusLine();
      if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        response.getEntity().writeTo(out);
        out.close();
        responseString = out.toString();
      } else {
        // closes the connection
        response.getEntity().getContent().close();
        throw new IOException(statusLine.getReasonPhrase());
      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return responseString;
  }

}




Java Source Code List

com.GameOfThrones.Trivia.core.CharacterToQuestionsMap.java
com.GameOfThrones.Trivia.core.GameCharacter.java
com.GameOfThrones.Trivia.core.HighScore.java
com.GameOfThrones.Trivia.core.OutOfQuestionsException.java
com.GameOfThrones.Trivia.core.QuestionCollection.java
com.GameOfThrones.Trivia.core.Question.java
com.GameOfThrones.Trivia.core.Session.java
com.GameOfThrones.Trivia.core.SimpleIterator.java
com.GameOfThrones.Trivia.core.TriviaGame.java
com.GameOfThrones.Trivia.data.HighScorePrefs.java
com.GameOfThrones.Trivia.data.RequestWebService.java
com.GameOfThrones.Trivia.data.StringsXMLFileData.java
com.GameOfThrones.Trivia.ui.AboutActivity.java
com.GameOfThrones.Trivia.ui.DynamicBackgroundActivity.java
com.GameOfThrones.Trivia.ui.GameActivity.java
com.GameOfThrones.Trivia.ui.HighScoreActivity.java
com.GameOfThrones.Trivia.ui.MainMenuActivity.java
com.GameOfThrones.Trivia.ui.ResultsActivity.java
com.GameOfThrones.Trivia.ui.TriviaSelectionActivity.java
com.GameOfThrones.Trivia.ui.music.MusicService.java
com.GameOfThrones.Trivia.util.GeneralAlgorithms.java
com.Spartacus.TriviaTest.TriviaMenuActivityTest.java
com.Spartacus.Trivia.utilTest.GeneralAlgorithmsTest.java