1. 程式人生 > >Android Things 開發

Android Things 開發

Create an Android Things Project
建立一個Android Things 應用程式

1,Prerequisites:開發的前提條件

Before you begin building apps for Things, you must:

1,Update your SDK tools to version 24 or higher The updated SDK tools enable you to build and test apps for Things.
2,Update your SDK with Android 7.0 (API 24) or higher The updated platform version provides new APIs for Things apps.
3,Create or update your app project In order to access new APIs for Things, you must create a project or modify an existing project that targets Android 7.0 (API level 24) or higher

1,更新sdk中build-tools的版本(24或者更高),更新後的sdk可以讓你構建和測試你的Things應用程式。
2,更新sdk中Android系統版本為Android 7.0(24)或者更高,它提供了開發Android Things應用程式新的API。
3,當你建立或者修改現有專案的時候,專案的API要是24或者更高,這樣你才能訪問Things的API。

2,Add the library
androidthings不是Android sdk中的一部分,它是以支援庫的方式存在,所以你要對其進行配置。
1,Add the dependency artifact to your app-level build.gradle file:

dependencies {
    ...
    provided 'com.google.android.things:androidthings:0.1-devpreview'
}

2,Add the things shared library entry to your app’s manifest file:

<application ...>
    <uses-library android:name="com.google.android.things"/>
    ...
</application>

uses-library :把程式包類裝載器中需要包含的庫程式碼通知系統

3,Declare a home activity
配置Activity

Action: ACTION_MAIN
Category: CATEGORY_DEFAULT
Category: IOT_LAUNCHER
<application
    android:label="@string/app_name">
    <uses-library android:name="com.google.android.things"/>
    <activity android:name=".HomeActivity">
        <!-- Launch activity as default from Android Studio -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

        <!-- Launch activity automatically on boot -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.IOT_LAUNCHER"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
</application>

至此怎麼建立一個Android Things應用程式開發完畢。

測試:寫一個activity,隨便列印log,按照以上配置,然後執行程式,看Console控制檯輸出。

在往下就是需要連線外設及和外設進行互動。