Internet of Things Competition-Android Study Notes (1) Android Concept

1. Android concept

 Android is an open mobile phone and computer operating system, based on the upper-level development of the Linux system.

What can android do?

Android can develop a variety of mobile applications APP, can also develop in-vehicle systems, etc. It has applications in every field and has played an important role in all major fields.

Second, the specific practice of Android in the Internet of Things competition

As described in the IOT entry instructions, IOT mobile application development: Based on the Android development platform, comprehensively use basic knowledge such as software engineering, Android, and embedded databases to complete the development of Android embedded applications, and examine the sensor technology and barcode technology of the contestants , ModBus protocol, gateway-based data acquisition technology, cloud platform-based device interface development and other comprehensive mobile design and development capabilities for the Internet of Things

Example: Development of restaurant environment monitoring subsystem

 

Three, Android development environment construction

Android environment construction requires software installation: a JDK, Android Studio, Android SDK

1. JDK installation and configuration environment

JAVA_HOME
E:\Java\JDK
Path
%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

2. Android Studio installation ( note that you need enough C drive )

Click net to install directly, choose not to import in the import section

3. The SDK will be loaded by default. If you want to choose your own SDK, you need to do the following steps

       File>>Project Structure >>SDK

4. Choose JDK location

       File>>Project Structure >>JDK

5. Install the virtual machine, click AVD Manager in the upper right corner (the analog phone running on the computer is referred to as AVD)

Five, run the first android application

File>>New Project

The created project structure is as follows

 

Reference documents

https://www.jianshu.com/p/4962b4eeec63

 

The project runs as follows

 

Six, possible problems when running android programs

1. Does not support 3.8

   Remove related imports in build.gradle

2. Unable to generate APK, delete the buid under app

3. Unable to survive apk, apk is empty

File>> setting>> buid >> Instent run check to remove

Seven, layout file introduction

ConstraintLayout layout overview:

ConstraintLayout is a constraint layout. From the mainstream layout, it will become the mainstream layout. It is very similar to the relative layout, but smoother than the relative layout. The constraint layout is the most suitable manual drag control layout.

Usage and attribute description:

1. Add project dependencies

implementation 'com.android.support.constraint:constraint-layout:2.0.1'

Eight, common android layout and controls

There are several common layouts in android: LinearLayout linear layout, RelativeLayout relative layout, AbsoluteLayout absolute layout, GridLayout grid layout.

1. Explanation of weight

Weight: is the proportion of the layout interface

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >
  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:background="#f47920">
  </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#2a5caa">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#faa755">
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <android.support.v7.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:text="请输入姓名"/>
    <android.support.v7.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:text="请输入密码"
        android:layout_height="60dp" />
    <android.support.v7.widget.AppCompatButton
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:text="登录"
        android:background="#00a6ac"/>
</LinearLayout>

Common android controls TextView Read-only text control Plain Text Inputable text control   

Button button control

 

Nine, Android project Src source code

There is a MainActivity.java file in the source code, the file is opened as follows

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //调用父类的onCreate方法
        super.onCreate(savedInstanceState);
        //设置layout中对应的XML文件activity_main
        setContentView(R.layout.activity_main);
        //获取登录按钮
       Button btn  =(Button) findViewById(R.id.Login);
      //设置按钮的监听事件
       btn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             //设置Text为本显示hello和日期
             TextView  show= (TextView) findViewById(R.id.show);
             show.setText("hello"+new java.util.Date());
           }
       });
    }
}

One: Set the xml file layout used by Activity

2: Get the button whose ID is R.id.Login

Three: Bind the event in the text box of R.id.show (where findViewById is actually equivalent to getElementById in js)

Java can actually be understood as an Android application resource dictionary

Res directory description: res stores all resources used by Android applications, including image resources, string resources, color resources, size resources, etc.

All resources will generate a resource list in R.java.

XML file introduction: XML file definition can be used to define common resources.

The form of the reference resource is as follows: @xml file name/defined xml file, such as using the color defined in color

Note: The defined id identifier does not require a special xml resource definition

@+id/<标识符名称>

AndroidManifest.xml manifest file: (You can configure permissions in mainfest, such as phone permissions, recording permissions, etc.)

<!--指定Android应用包名 该包名可用于唯一表示该应用-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.administrator.demo2">
    <!--指定Android应用标签、图标等-->
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <!--定义Android应用的一个组件:-->
        <activity android:name=".MainActivity">
            <intent-filter>
                <!--指定Activity是程序入口-->
                <action android:name="android.intent.action.MAIN" />
                 <!--指定加载应用时运行该Activity-->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

Guess you like

Origin blog.csdn.net/weixin_44893902/article/details/108634067