树莓派Android Things物联网开发:创建一个Things项目

【转载请注明出处: http://blog.csdn.net/leytton/article/details/77854144

《树莓派Android Things物联网开发》系列文章专栏 http://blog.csdn.net/column/details/17741.html

树莓派Android Things物联网开发:入门及资料汇总

树莓派Android Things物联网开发:创建一个Things项目

树莓派Android Things物联网开发:树莓派GPIO引脚图

树莓派Android Things物联网开发:按键中断及消抖

树莓派Android Things物联网开发:已知Bug发行说明

树莓派Android Things物联网开发:GitHub案例程序汇总


Android Things应用程序结构与Android手机或平板电脑相同。这意味着你可以修改现有的App直接在Android Things中运行,或者你可以基于之前掌握的Android技术来开Things应用。

本课程介绍了Android Things开发环境准备工作,以及一些必要的修改,以使应用在Android Things中运行。

准备工作


在开始构建Things应用程序的之前,你必须:

添加依赖库


Android Things的API不包含在Android SDK中。我们要声明Things的依赖库:

  1. build.gradle文件中添加依赖库:

    dependencies {
        ...
        provided 'com.google.android.things:androidthings:0.5.1-devpreview'
    }
    
  2. 在AndroidManifest.xml添加共享库:

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

声明入口Activity


想要应用程序在Android Things嵌入式设备中开机启动,那么就必须在其AndroidManifest.xml文件中声明作为主入口点,并且添加intent-filter包含以下属性:

为了便于开发,这个Activity也应该包括 CATEGORY_LAUNCHER 这个intent-filter,Android Studio在部署或调试时会启动它作为默认入口。

<application
    android:label="@string/app_name">
    <uses-library android:name="com.google.android.things"/>
    <activity android:name=".HomeActivity">
        <!-- Android Studio 默认启动的Activity -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

        <!-- 开机后自动启动的Activity -->
        <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>

PS:如果本文对您有帮助,请点个赞让我知道哦~微笑


原文阅读需要科学上网

摘自https://developer.android.com/things/training/first-device/create-studio-project.html

Create an Android Things Project

Things apps use the same structure as those designed for phones and tablets. This similarity means you can modify your existing apps to also run on embedded things or create new apps based on what you already know about building apps for Android.

This lesson describes how to prepare your development environment for Android Things, and the required changes to enable app to run on embedded things.

Prerequisites


Before you begin building apps for Things, you must:

Add the library


Android Things devices expose APIs through support libraries that are not part of the Android SDK. To declare the Things Support Library dependency in your app:

  1. Add the dependency artifact to your app-level build.gradle file:

    dependencies {
        ...
        provided 'com.google.android.things:androidthings:0.5.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>
    

Declare a home activity


An application intending to run on an embedded device must declare an activity in its manifest as the main entry point after the device boots. Apply an intent filter containing the following attributes:

For ease of development, this same activity should include a CATEGORY_LAUNCHER intent filter so Android Studio can launch it as the default activity when deploying or debugging.

<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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值