Android things: Roll up the sleeves to create the first things project

Source: Internet
Author: User

http://blog.csdn.net/p106786860/article/details/60161020

——————————————————————————————————————————————————————————————————————————————————————

in the previous chapters , we've used the official Sample-simplepio project's Blink module to show you how to import and run an off-the-shelf Android things project. So in this chapter, let's show you how to create, develop, and run an Android things project from scratch.
1. Pre-Preparation
Before you start creating your Android things project, you must do the following:
  update your SDK tool to 24 or later, The updated SDK tool allows you to build and test things apps.
  Update your SDK for Android 7.0 (API 24) or higher, the updated platform version provides a new API for the things app.
Android studio->tools->android->sdk Manager, such as:


2. Create a project
We've seen the development environment, development tools, project structure, and Android projects of the Android Things project to be consistent, in fact, it's an Android project. Then we create a new Andoird project Thingsdemo.

note: To create and update your app project, in order to access the things new API, you must either create a project or modify an existing project that has a target of Android7.0 (API 24) or higher;
4. Add Library
The android things device exposes the API through the support library, which is not part of the Android SDK. Declare things support library dependencies in your app.
Add dependency mappings to your app-level build.gradle file:
thingsdemo\app\build.gradle

[Plain]View Plain copy
    1. Apply plugin: ' Com.android.application '
    2. Android {
    3. ... ...
    4. }
    5. dependencies {
    6. Compile Filetree (dir: ' Libs ', include: [' *.jar '])
    7. ... ...
    8. Provided ' Com.google.android.things:androidthings:0.1-devpreview '
    9. }

Add the things shared library entry to your manifest file:
Thingsdemo\app\src\main\androidmanifest.xml

[HTML]View Plain copy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="Com.chengxiang.thingsdemo">
  4. <application
  5. android:allowbackup="true"
  6. android:icon="@mipmap/ic_launcher"
  7. android:label="@string/app_name"
  8. android:supportsrtl="true"
  9. android:theme="@style/apptheme">
  10. <uses-library android:name="com.google.android.things"/>
  11. ... ...
  12. </Application>
  13. </manifest>

5. Declaring the main activity
An application that wants to run into an embedded device must declare an activity in the manifest file as the main portal after the system is booted. Apply the intent Filger that contains the following attributes;
Action:action_main
Category:category_defauult
Category:iot_launcher
Thingsdemo\app\src\main\androidmanifest.xml

[HTML]View Plain copy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="Com.chengxiang.thingsdemo">
  4. <uses-library android:name="com.google.android.things"/>
  5. <application
  6. ... ...
  7. android:theme="@style/apptheme">
  8. <activity android:name=". Mainactivity ">
  9. <intent-filter>
  10. <action android:name="Android.intent.action.MAIN"/>
  11. <category android:name="Android.intent.category.LAUNCHER"/>
  12. </intent-filter>
  13. <!--Launch activity automatically on boot --
  14. <intent-filter>
  15. <action android:name="Android.intent.action.MAIN"/>
  16. <category android:name="Android.intent.category.IOT_LAUNCHER"/>
  17. <category android:name="Android.intent.category.DEFAULT"/>
  18. </intent-filter>
  19. </Activity>
  20. </Application>
  21. </manifest>

6. Compile and run
Here we try to compile and run the project using the Gradle build task, run as follows:

[Plain]View Plain copy
  1. C:\users\chengxiang.peng.qunarservers\androidthingssources\thingsdemo>gradle App:installDebug
  2. Starting a Gradle Daemon, 1 incompatible and 2 stopped daemons could not being reused, use--status for details
  3. Incremental Java compilation is an incubating feature.
  4. The Taskinputs.source (Object) method has been deprecated and are scheduled to being removed in Gradle 4.0. Please use Taskinputs.file (Object). Skipwhenempty () instead.
  5. : App:prebuild Up-to-date
  6. ... ...
  7. : App:installdebug
  8. Unable to get density for device iot_rpi3-7.0
  9. Installing APK ' app-debug.apk ' on ' iot_rpi3-7.0 ' for App:debug
  10. Installed on 1 device.
  11. BUILD Successful
  12. Total time:1 mins 31.038 secs
[Plain]View Plain copy
    1. C:\USERS\CHENGXIANG.PENG.QUNARSERVERS\ANDROIDTHINGSSOURCES\THINGSDEMO>ADB Shell am Start com.chengxiang.thingsdemo/. Mainactivity
    2. starting:intent {act=android.intent.action.main Cat=[android.intent.category.launcher] cmp= com.chengxiang.thingsdemo/. Mainactivity}



Tip 1: run adb shell am start com.chengxiang.thingsdemo/. mainactivity command, error error:unknown host service
Analysis 1: because running ADB naming needs to use 5037 port, should be a program occupied by this port, so error.
handles 1: finds the program that occupies the port and kills it.

1. New technology, future! You are welcome to pay attention to "1024 Workshop" service number "1024 workshop" Micro Shop and buy what you want at once. 3. Add "Android things Development" QQ discussion Group and learn together hi. (Don't hesitate!) Enjoy the scan or long press! )

Android things: Roll up the sleeves to create the first things project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.