• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps what it doesn't read html code

hno2005

Newbie
Hi
I wanna to read data from Internet , this is my code :
Code:
public class Main extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		TextView tv=(TextView) findViewById(R.id.textView1);
		
		/*try {
			GetDataInternet get=new GetDataInternet();
			String returned;
			returned = get.getdata();
			tv.setText(returned);
		} catch (Exception e) {
			// TODO Auto-generatesd catch block
			e.printStackTrace();
		}
		*/
		try {
			URL url=new URL ("http://google.com");
			URLConnection conn=url.openConnection();
			BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));  
			String line="";
			while((line=reader.readLine())!=null){  
				tv.append(line);
			}
			 
		} catch (Exception e) {
			// TODO: handle exception

		}
	
	
	}
it should read and write on a textview

manifest.xml
Code:
 <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
    ......

and this is my textview

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="16dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

could you please help me what It doesn't get anything from internet ?

thanks
 
If I were you, I'd use droidQuery.
Like so:
PHP:
$.ajax(new AjaxOptions().context(this).url("http://google.com").dataType("text").success(new Function() {
    @Override
    public void invoke($ d, Object... params) {
        String fileContents = (String) params[0];
        Log.i("Got this:", fileContents);
    }
}).error(new Function() {
    @Override
    public void invoke($ d, Object... params) {
        AjaxError error = (AjaxError) params[0];
        Log.e("Ajax", "Error " + error.status + ": " + error.reason);
    }
}));
 
Back
Top Bottom