Android application

In this section, we will see the android application. In your folder, open the file of the project about Android Studio.

We have here the XML code generated in the code of the interface:

FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 
    tools:ignore="MergeRootFrame"> 
 
    <WebView 
        android:id="@+id/activity_main_webview" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
</FrameLayout> 

Java class

When we create the project, some class are generated automatically, as we will see in the following lines:

  1. Name of the class:
            import android.webkit.WebView; 
    
  2. Main class:
        public class MonitoringTemperatureHumidity extends
          ActionBarActivity { 
 
            private WebView mWebView; 

In this part of the code from the android application, we request for the value:

mWebView.loadUrl("http://192.168.1.110/temperature");
mWebView.loadUrl("http://192.168.1.110/humidity");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_monitoring_temperature_humidity);

We define the objects that will be included in the main activity, in this case it is the mWebView control, it is defined in the main activity of the application:

    mWebView = (WebView)  findViewById(R.id.activity_main_webview);
    mWebView.loadUrl("http://192.168.1.110/humidity");
}

Permission of the application

In order to give permission to the application to execute networking permissions, it's necessary that we add the following line in the Android Manifest file:

<uses-permission android:name="android.permission.INTERNET"/>

When the application is debugged and installed on the device, we will see the following results on our screen, displaying the value of the temperature:

Permission of the application

The value of the humidity:

Permission of the application
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.174.133