【转载请注明出处: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应用程序的之前,你必须:

  • 更新SDK工具到25.0.3或更高版本 更新版本的SDK工具,可以帮您构建和测试应用应用。
  • 更新SDK到Android 8.0(API 26)或更高版本 更新版本的SDK平台提供新的Things应用API。
  • 创建或更新您的应用项目, 为了在新的Things应用API,创建的项目或者已有项目的SDK版本必须升级到Android 8.0(API26)或更高。

添加依赖库


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-libraryandroid:name="com.google.android.things"/>...</application>

注意:添加provided依赖,能确保构建工具在编译时不会将共享库复制到APK中。加入<uses-library> 能使这个共享库在应用程序运行时有效。总之,这些设置能使您的应用程序使用设备系统提供的共享库。

声明入口Activity


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

  • Action: ACTION_MAIN
  • Category: CATEGORY_DEFAULT
  • Category: IOT_LAUNCHER

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

<applicationandroid:label="@string/app_name"><uses-libraryandroid:name="com.google.android.things"/><activityandroid:name=".HomeActivity"><!-- Android Studio 默认启动的Activity --><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter><!-- 开机后自动启动的Activity --><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.IOT_LAUNCHER"/><categoryandroid: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:

  • Update your SDK tools to version 25.0.3 or higher The updated SDK tools enable you to build and test apps for Things.
  • Update your SDK with Android 8.0 (API 26) or higher The updated platform version provides new APIs for Things apps.
  • 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 8.0 (API level 26) or higher.

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-libraryandroid:name="com.google.android.things"/>...</application>

Note: Add the provided dependency to ensure that the build tools don't copy the shared library into the APK at compile time. Add <uses-library> to make this prebuilt library available to the app's classpath at run time. Together, these additions allow you to build against an on-device, shared library.

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:

  • Action: ACTION_MAIN
  • Category: CATEGORY_DEFAULT
  • CategoryIOT_LAUNCHER

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.

<applicationandroid:label="@string/app_name"><uses-libraryandroid:name="com.google.android.things"/><activityandroid:name=".HomeActivity"><!-- Launch activity as default from Android Studio --><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter><!-- Launch activity automatically on boot --><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.IOT_LAUNCHER"/><categoryandroid:name="android.intent.category.DEFAULT"/></intent-filter></activity></application>

转载于:https://www.cnblogs.com/leytton/p/8253241.html

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

  1. [置顶]树莓派Android Things物联网开发:入门及资料汇总

    [转载请注明出处: http://blog.csdn.net/leytton/article/details/77848430] <树莓派Android Things物联网开发>系列文章专 ...

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

    [转载请注明出处:http://blog.csdn.net/leytton/article/details/78275085] <树莓派Android Things物联网开发>系列文章专栏 ...

  3. Android应用程序开发——创建应用程序

    建立你的第一个应用程序 欢迎来到Android应用程序开发教程! 本教程将教你如何建立你的第一个Android 应用程序.你会学习如何创建一个Android项目,如何运行可调试的应用程序.还会学习到A ...

  4. 在android studio中如何创建一个类来继承另外一个类_在Android使用Transition API检测用户活动...

    在当今世界,移动设备是我们日常生活中必不可少的一部分,我们在走路.跑步.开车以及其他许多活动时都会使用移动设备. 了解用户拿着手机的时候在做什么,可以让你的应用程序根据用户的动作进行直观的调整.对于某 ...

  5. 如何在物联网平台创建一个千里传音产品?

    创建项目 登录阿里云官网,选择产品阿里云IoT平台->企业物联网平台->控制台->增值服务->选购增值服务->扩展与定制服务,找到千里传音服务,点击免费试用开通该服务.开 ...

  6. 从零开始创建一个uni-app项目

    从零开始创建一个uni-app项目 新建项目 目录说明 文件结构 安装uview 安装ucharts 新建项目 创建uni-app项目首先要下载HBuilder X,HBuilderX下载地址: 下载 ...

  7. 创建一个springMVC项目总结

    创建一个springMVC项目总结 1.如何搭建起一个Spring mvc的环境并运行程序. 参考:http://www.cnblogs.com/bigdataZJ/p/springmvc1.html ...

  8. 创建python虚拟环境,安装django,创建一个django项目,在项目中创建一个应用(ubuntu16.04)...

    一.创建python虚拟环境 首先,为什么要创建python的虚拟环境? 因为,在实际的项目开发中,每个项目使用的框架库并不一样,或使用框架的版本不一样,这样需要 我们根据需求不断的更新或卸载相应的库 ...

  9. 把python37添加到环境变量配置_关于在win 10上成功创建一个Django项目时遇到django-admin的手动配置环境变量问题。...

    前言 初学Python Web 在创建第一个Djang项目的时候出现了很多的问题,今天和大家分享并记录一下这次艰难的历程! 一.官网下载Python以及安装Django 1.Python的下载安装 链 ...

最新文章

  1. 2019年3月8日比赛(知网是什么)
  2. win10子系统ubuntu文件夹位置_win10子系统(WSL)自定义安装路径
  3. 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
  4. python嵌入到C++中
  5. 漫画|你还记得原生的JDBC怎么连接数据库吗?
  6. image1载入大图片时如果stretch=true,image1会显示出大图片的缩图,那么如何将这个缩图镜像复制一份赋值给另一个image2的picture呢?...
  7. 每天CookBook之Python-003
  8. 2021-2022年数学建模资料汇总——建模软件篇
  9. 机器人SCI期刊及其特点、评价、投稿之我见
  10. 如何导入以前的qq聊天记录
  11. 游戏音效制作的过程中,需要研发公司怎么配合?
  12. 如何把Windows主机中的文件拉到centOS虚拟机中
  13. 【网络协议模糊测试实战】使用sulley对PCManFTP进行模糊测试
  14. 资讯的服务器维护指什么,资讯
  15. 如何用viso画波浪线、以及带箭头的波浪线。
  16. java execute、executeQuery和executeUpdate之间的区别
  17. 中职双师型教师计算机培训总结,中职教师教学能力远程培训总结范文(精选3篇)...
  18. wsl Failed to get D-Bus connection: Operation not permitted
  19. XPS文件转换为PDF不再愁!全新XPS/EPS文档处理神器Aspose.Page来啦!
  20. 从源码看std::weak_ptr

热门文章

  1. tag标签[置顶] 高级NFC
  2. 15个新鲜的单页网站设计实例
  3. c语言基础知识pdf下载,C语言主基础知识.pdf
  4. 静茹docker容器的几种方法_Docker介绍及使用
  5. mysql 锁语句_mysql-笔记 事务 锁 语句
  6. 不使用powerdesigner手工绘制用例图例题详解
  7. 查找手机型号云服务器,查找手机型号云服务器
  8. 适合初学者的java书籍
  9. novaclient的api调用流程与开发
  10. Android Monkey使用