Using java Syntax Highlighting
- package se.eclaesson.spelradion;
- import android.app.TabActivity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import android.os.Bundle;
- import android.widget.TabHost;
- import android.app.AlertDialog.Builder;
- import se.eclaesson.spelradion.HttpHelper.*;
- public class Spelradion extends TabActivity {
- HttpClient http;
- HttpGet get;
- HttpResponse response;
- Builder alertb;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- TabHost mTabHost = getTabHost();
- mTabHost.addTab(mTabHost.newTabSpec("tab_senaste").setIndicator("Senaste").setContent(R.id.LinearLayout01));
- mTabHost.addTab(mTabHost.newTabSpec("tab_visaalla").setIndicator("Visa Alla").setContent(R.id.textview2));
- mTabHost.addTab(mTabHost.newTabSpec("tab_sok").setIndicator("Sök").setContent(R.id.textview3));
- mTabHost.setCurrentTab(0);
- //Set up the Alert Builder
- alertb = new Builder(getBaseContext());
- alertb.setTitle("Ett fel har uppstått");
- //Set up HttpClient
- http = new DefaultHttpClient();
- get = new HttpGet("http://spelradion.libsyn.com/rss");
- try
- {
- response = http.execute(get);
- //System.out.print("123");
- System.out.print(HttpHelper.request(response));
- }
- catch(Exception e)
- {
- alertb.setMessage("Kunde inte ansluta till Spelradion.");
- alertb.show();
- }
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
The HtppHelper class:
Using java Syntax Highlighting
- package se.eclaesson.spelradion.HttpHelper;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import org.apache.http.HttpResponse;
- public class HttpHelper {
- public static String request(HttpResponse response){
- String result = "";
- try{
- InputStream in = response.getEntity().getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- StringBuilder str = new StringBuilder();
- String line = null;
- while((line = reader.readLine()) != null){
- str.append(line + "\n");
- }
- in.close();
- result = str.toString();
- }catch(Exception ex){
- result = "Error";
- }
- return result;
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4




