Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>add this in your manifest file..</p> <pre><code> &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; </code></pre> <p>this example is to display the textfile in android.. it uses asynctask </p> <pre><code> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class Display extends Activity implements OnClickListener { Button button; TextView outputText; public static final String URL = "URL"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewsById(); button.setOnClickListener(this); } private void findViewsById() { button = (Button) findViewById(R.id.button); outputText = (TextView) findViewById(R.id.outputTxt); } public void onClick(View view) { GetXMLTask task = new GetXMLTask(); task.execute(new String[] { URL }); } private class GetXMLTask extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... urls) { String output = null; for (String url : urls) { output = getOutputFromUrl(url); } return output; } private String getOutputFromUrl(String url) { StringBuffer output = new StringBuffer(""); try { InputStream stream = getHttpConnection(url); BufferedReader buffer = new BufferedReader( new InputStreamReader(stream)); String s = ""; while ((s = buffer.readLine()) != null) output.append(s); } catch (IOException e1) { e1.printStackTrace(); } return output.toString(); } // Makes HttpURLConnection and returns InputStream private InputStream getHttpConnection(String urlString) throws IOException { InputStream stream = null; URL url = new URL(urlString); URLConnection connection = url.openConnection(); try { HttpURLConnection httpConnection = (HttpURLConnection) connection; httpConnection.setRequestMethod("GET"); httpConnection.connect(); if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { stream = httpConnection.getInputStream(); } } catch (Exception ex) { ex.printStackTrace(); } return stream; } @Override protected void onPostExecute(String output) { outputText.setText(output); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload