+ 24

How can I read text that is on a remote server and shows it as TextView in Android programming?

I need my APP read a remote text and show it in a TextView.

22nd Feb 2018, 7:35 PM
Giovane de Macedo Borges
Giovane de Macedo Borges - avatar
4 Answers
+ 2
maybe u can find ur answer at Android developer site search for server connection or downloading data from web
22nd Feb 2018, 7:57 PM
Farshaad Heydari
Farshaad Heydari - avatar
+ 22
Finally i have finished. public class MainActivity extends Activity { private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.texto); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } try { URL url = new URL("http://g.txt"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { tv.setText(str); } in.close(); } catch (MalformedURLException e) { } catch (IOException e) { } } }
22nd Feb 2018, 8:05 PM
Giovane de Macedo Borges
Giovane de Macedo Borges - avatar
+ 19
āœŒ
22nd Feb 2018, 8:08 PM
Giovane de Macedo Borges
Giovane de Macedo Borges - avatar
+ 2
cool for you šŸ™‚
22nd Feb 2018, 8:07 PM
Farshaad Heydari
Farshaad Heydari - avatar