1) Добавим EditText, Button, TextView
2) Добавим код:
3) Добавляем User Persmission типа android.permission.INTERNET в AndroidManifest.xml на вкладке Permissions.
2) Добавим код:
package com.example.inet; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final EditText edit1 = (EditText) findViewById(R.id.editText1); final Button but1 = (Button) findViewById(R.id.button1); final TextView text1 = (TextView) findViewById(R.id.textView1); but1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub try { URL url = null; url = new URL(edit1.getText().toString()); URLConnection con1 = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(con1.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { text1.append(line); } } catch (Exception e) { } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
3) Добавляем User Persmission типа android.permission.INTERNET в AndroidManifest.xml на вкладке Permissions.