First, Android Things
Android Things is simply an Android-based intelligent Internet of Things (IoT) operating system.
Its vision is to connect millions of devices. Android Things is the brain of the Internet of Things, using the open protocol Weave to talk to a wide range of sensors/peripherals.
Simply put, Android Things allows developers to develop embedded devices using Android development tools.
If you can build an app, you can build a device. As long as you can build apps, you can build smart devices.
To develop smart devices using Android requires learning NDK /JNI knowledge. To develop smart devices using AndroidThings can be achieved by calling the API encapsulated by Things.
Android Things extends the Core Android Framework and provides additional apis through the Things Support Library. Allows developers to integrate hardware that is not normally found in mobile devices such as phones.
Second, AndroidThings + Raspberry PI 3 enables remote control of LED lights
2.1: Preparing hardware
1: Raspberry Pi 3 development board
2: one LED lamp
3:8G ONE SDcard (for burning images)
2.2: Image Creation
2.2.1: download
With the platform you have to make an image to install the system. The first is to download the image, the website is as follows: image download address
When unzipped, this is iot_rpi3.img. Considering that some friends can not turn over the wall, here Baidu network disk provides a link: pan.baidu.com/s/1kVHW2OZ password: CRQG
2.2.2: Burn mirror
You can download Etcher, the official raspberry PI tool
Download Etcher and install it
Select the Android Things system files to swipe in, such as the downloaded image.zip, select the target drive (insert the TF card into your computer), and click “Flash! The button brushes into the system
Brush into the
It will be verified after brushing in
After verification, TF card pops up and the raspberry PI is inserted to start the system
Third, project creation
I’m using Android Studio2.3.3
The project structure
Add the dependent
(1) Add the following dependencies to the build.gradle file in the app module
// Add Things support pack
provided'com. Google. Android. Things: androidthings: 0.2 devpreview'
provided'com.google.android.things:androidthings:+'
// MQTT
compile'org. Eclipse. Paho: org. Eclipse paho. Client. Mqttv3:1.1.0'
compile'Commons - codec: the Commons - the codec: 1.5'
Copy the code
Remote control of the LED light switch is achieved by using Ali’s MQTT messaging mechanism
(2) Add shared library to application node in manifest.xml file:
Note: Adding the Provided dependency ensures that the build tool does not copy the shared library into the APK at compile time. Joining makes the shared library available while the application is running. Together, these Settings enable your applications to use the shared libraries provided by the device system.
(3) Declare the main Activity
To start an application on an Android Things embedded device, you must declare it as the main entry in its Androidmanifest.xml file.
(4) Initialize IO in the main Activity
Adb install -g XXX. APK (-g is the permission declared in manifest.xml); No permission exception will be reported
The result after realization: the LED light can be switched on and off by a remote control APP