Guest User

Untitled

a guest
Jan 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. String VersioRemota;
  3. String Temp;
  4. TextView Tv1;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate ( savedInstanceState );
  8. setContentView ( R.layout.activity_main );
  9.  
  10. new Thread(new Runnable(){
  11. @Override
  12. public void run(){
  13. URL url = null;
  14.  
  15. try {
  16. url = new URL("http://www.inforatge.com/alzira/main/wdl/clientraw.txt");
  17.  
  18. BufferedInputStream bis = new BufferedInputStream(url.openStream());
  19. byte[] buffer = new byte[730];
  20. int bytesRead = 0;
  21. bytesRead = bis.read(buffer);
  22. VersioRemota = new String(buffer, 0, bytesRead);
  23. String Datos[] = VersioRemota.split(" ");
  24. Temp = Datos[4];
  25.  
  26. bis.close();
  27.  
  28. } catch (MalformedURLException e) {
  29. Log.w("", "MALFORMED URL EXCEPTION");
  30. } catch (IOException e) {
  31. Log.w(e.getMessage(), e);
  32. }
  33.  
  34. }
  35.  
  36. }).start();
  37. Tv1=(TextView) findViewById ( R.id.TextView1 );
  38. Tv1.setText(Temp);
  39.  
  40. }
  41.  
  42.  
  43. }
  44.  
  45. <?xml version="1.0" encoding="utf-8"?>
  46. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  47. xmlns:app="http://schemas.android.com/apk/res-auto"
  48. xmlns:tools="http://schemas.android.com/tools"
  49. android:layout_width="match_parent"
  50. android:layout_height="match_parent"
  51. tools:context=".MainActivity">
  52.  
  53. <TextView
  54. android:id="@+id/TextView1"
  55. android:layout_width="180dp"
  56. android:layout_height="61dp"
  57. android:layout_marginStart="116dp"
  58. android:layout_marginLeft="116dp"
  59. android:layout_marginTop="80dp"
  60. android:text="temperatura"
  61. android:textSize="30sp"
  62. android:textStyle="bold"
  63. app:layout_constraintStart_toStartOf="parent"
  64. app:layout_constraintTop_toTopOf="parent"
  65. tools:textColor="@color/colorPrimaryDark" />
  66.  
  67. public class MainActivity extends AppCompatActivity {
  68. String VersioRemota;
  69. String Temp;
  70. TextView Tv1;
  71.  
  72. @Override
  73. protected void onCreate(Bundle savedInstanceState) {
  74. super.onCreate(savedInstanceState);
  75. setContentView(R.layout.activity_main);
  76. Tv1 = (TextView) findViewById(R.id.txtPrueba);
  77. new Thread(new Runnable() {
  78. @Override
  79. public void run() {
  80. URL url = null;
  81.  
  82. try {
  83. url = new URL("https://www.inforatge.com/alzira/main/wdl/clientraw.txt");
  84.  
  85. BufferedInputStream bis = new BufferedInputStream(url.openStream());
  86. byte[] buffer = new byte[730];
  87. int bytesRead = 0;
  88. bytesRead = bis.read(buffer);
  89. VersioRemota = new String(buffer, 0, bytesRead);
  90. String Datos[] = VersioRemota.split(" ");
  91. Temp = Datos[4];
  92. runOnUiThread(new Runnable() {
  93. public void run() {
  94. Tv1.setText(Temp);
  95. }
  96. });
  97.  
  98. bis.close();
  99.  
  100. } catch (MalformedURLException e) {
  101. Log.w("error**", "MALFORMED URL EXCEPTION");
  102. } catch (IOException e) {
  103. Log.w(e.getMessage(), e);
  104. }
  105.  
  106. }
  107.  
  108. }).start();
  109. //
  110. //Tv1.setText(Temp);
  111. }
  112. }
Add Comment
Please, Sign In to add comment