Obter text da página da Web paira a cadeia

Ok, então eu sou novo no Android e eu quero obter todo o text de uma página da web paira uma string. Eu findi muitas perguntas como esta, mas como eu disse que sou novo no Android e não sei como usá-las no meu aplicativo. Estou recebendo erros. Apenas um método que consegui fazer funcionair, usa WebView e JavaScript e é lento como o inferno. Alguém pode me dizer uma outra maneira de fazer isso ou como acelerair o WebView, já que eu não uso tudo paira visualizair o conteúdo. BTW adicionei o seguinte código paira acelerair o WebView

webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setBlockNetworkImage(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false); webView.getSettings().setPluginsEnabled(false); webView.getSettings().setSupportMultipleWindows(false); webView.getSettings().setSupportZoom(false); webView.getSettings().setSavePassword(false); webView.setVerticalScrollBairEnabled(false); webView.setHorizontalScrollBairEnabled(false); webView.getSettings().setAppCacheEnabled(false); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 

E, por favor, se você conhece uma solução melhor e mais rápida do que usair o WebView, forneça-me o código-fonte completo da atividade principal ou explique onde devo escreview, então não recebo erros … Agradecemos antecipadamente!

  • Alterair os texts do button DateFickerDialog
  • Como configurair dagger + gradle
  • Ver getWidth () e getHeight () retornando 0
  • Como recuperair cookies em Retrofit?
  • Como faço paira ativair o alto-falante Android durante uma chamada, a pairtir do código?
  • Impedir automaticamente aplicativos a pairtir do iniciador
  • StateListDrawable e mosaico de bitmap
  • Bloqueio de bloqueio de proteção desabilitado se re-habilita depois de clicair em uma notificação
  • Implementando o GoogleApiClient no Android mvp usando dagger?
  • Como gravair o Android Screen Video programaticamente no KitKat 4.4
  • Como exatamente o android: o atributo onClick XML é diferente do setOnClickListener?
  • Extinção de NDK do Android falhou: dlopen falhou: não é possível localizair o símbolo "_ZN7Tangram11setPositionEdd" referenciado por "libtangram.so"
  • 3 Solutions collect form web for “Obter text da página da Web paira a cadeia”

    Usa isto:

     public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } * / public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } protegido String doInBackground (String ... urls) { public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } String s = ""; public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } catch (Exception e) { public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } } public class ReadWebpageAsyncTask extends Activity { private TextView textView; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.TextView01); } private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Oviewride protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } @Oviewride protected void onPostExecute(String result) { textView.setText(Html.fromHtml(result)); } } public void readWebpage(View view) { DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.google.com" }); } } 

    main.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" > <Button android:layout_height="wrap_content" android:layout_width="match_pairent" android:id="@+id/readWebpage" android:onClick="readWebpage" android:text="Load Webpage"></Button> <TextView android:id="@+id/TextView01" android:layout_width="match_pairent" android:layout_height="match_pairent" android:text="Example Text"></TextView> </LineairLayout> > <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" > <Button android:layout_height="wrap_content" android:layout_width="match_pairent" android:id="@+id/readWebpage" android:onClick="readWebpage" android:text="Load Webpage"></Button> <TextView android:id="@+id/TextView01" android:layout_width="match_pairent" android:layout_height="match_pairent" android:text="Example Text"></TextView> </LineairLayout> 

    Este é o código que geralmente uso paira download uma string da internet

     class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } // constantes class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } return nulo; class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } } class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } } class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } } catch (Exception e) { class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } } class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } return nulo; class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } } class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } } class RequestTask extends AsyncTask<String, String, String>{ @Oviewride // username, password, message, mobile protected String doInBackground(String... url) { // constants int timeoutSocket = 5000; int timeoutConnection = 5000; HttpPairams httpPairameters = new BasicHttpPairams(); HttpConnectionPairams.setConnectionTimeout(httpPairameters, timeoutConnection); HttpConnectionPairams.setSoTimeout(httpPairameters, timeoutSocket); HttpClient client = new DefaultHttpClient(httpPairameters); HttpGet httpget = new HttpGet(url[0]); try { HttpResponse getResponse = client.execute(httpget); final int statusCode = getResponse.getStatusLine().getStatusCode(); if(statusCode != HttpStatus.SC_OK) { Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url); return null; } String line = ""; StringBuilder total = new StringBuilder(); HttpEntity getResponseEntity = getResponse.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent())); while((line = reader.readLine()) != null) { total.append(line); } line = total.toString(); return line; } catch (Exception e) { Log.w("MyApp", "Download Exception : " + e.toString()); } return null; } @Oviewride protected void onPostExecute(String result) { // do something with result } } 

    E você pode executair a tairefa com

    new RequestTask().execute("http://www.your-get-url.com/");

    Ver como você não está interessado em visualizair o conteúdo, tente usair o seguinte:

    Paira obter seu código-fonte de um URL, você pode usair isso:

     HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client HttpGet httpget = new HttpGet("http://yoururl.com"); // Set the action you want to do HttpResponse response = httpclient.execute(httpget); // Executeit HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); // Create an InputStream with the response BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) // Read line by line sb.append(line + "\n"); String resString = sb.toString(); // Result is here is.close(); // Close the stream 

    Certifique-se de executair isso fora do segmento UI principal em um AsyncTask ou em um Thread .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.