+ 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.
4 Answers
+ 2
maybe u can find ur answer at Android developer site
search for server connection or downloading data from web
+ 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) { }
}
}
+ 19
ā
+ 2
cool for you š