[Permissions] Read a website to an TextView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

[Permissions] Read a website to an TextView

Postby NelsonPRSousa » Sat Nov 02, 2013 2:57 am

Hi guys,

I am new here; First of all I wish you all the best and hope I can learn something with you! :)

I am with a problem: I can not read html from a website with my Android app. I think the problem is because of Internet permissions.

HttpExample (who is launched)
Code: Select all
package com.example.httpexample;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class HttpExample extends Activity {

   TextView httpStuff;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_http_example);
      
      httpStuff = (TextView) findViewById(R.id.tvHttp);
      GetMethodEx test = new GetMethodEx();
      String returned;
      httpStuff.setText("Debugging 1 - onCreate");
      try {
         returned = test.getInternetData();
         httpStuff.setText(returned);
      } catch (Exception e) {
         httpStuff.setText("Debbuging 3 - catch");
         e.printStackTrace();
      }
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.http_example, menu);
      return true;
   }

}

Right here I tried to debugging and my textview get the exception from catch.

GetMethodEx
Code: Select all
package com.example.httpexample;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;

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;

public class GetMethodEx {
   
   public String getInternetData() throws Exception{
      BufferedReader in = null;
      String data = null;
      try{
         HttpClient client = new DefaultHttpClient();
         URI website = new URI("http://www.mybringback.com/");
         HttpGet request = new HttpGet();
         request.setURI(website);
         HttpResponse response = client.execute(request);
         in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
         StringBuffer sb = new StringBuffer("");
         String l = "";
         String nl = System.getProperty("line.separator");
         while((l = in.readLine()) != null){
            sb.append(l + nl);
         }
         in.close();
         data = sb.toString();
         return data;
      }finally{
         if(in != null){
            try{
               in.close();
               return data;
            } catch(Exception e) {
               e.printStackTrace();
            }
         }
      }
   }
   
}


Manifest
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.httpexample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.httpexample.HttpExample"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Hope you guys can help me. Thank you.
Nelson.
NelsonPRSousa
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Nov 02, 2013 2:55 am

Top

Re: [Permissions] Read a website to an TextView

Postby nadirchine » Tue Nov 05, 2013 1:32 pm

how i can parse data from a site which has no RSS ?
nadirchine
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Nov 05, 2013 12:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 9 guests