Hi
I wanna to read data from Internet , this is my code :
it should read and write on a textview
manifest.xml
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
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
}
}
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