博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
树莓派Android Things物联网开发:创建一个Things项目
阅读量:4633 次
发布时间:2019-06-09

本文共 3564 字,大约阅读时间需要 11 分钟。

【转载请注明出处: 

《树莓派Android Things物联网开发》系列文章专栏 

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

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

准备工作


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

  •  更新版本的SDK工具,可以帮您构建和测试应用应用。
  •  更新版本的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添加共享库:

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

声明入口Activity


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

  • Action: 
  • Category: 
  • Category: IOT_LAUNCHER

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

   
   
       
       
           
           
       
       
       
           
           
           
       
   

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:

  •  The updated SDK tools enable you to build and test apps for Things.
  •  The updated platform version provides new APIs for Things apps.
  •  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:

       
        ...
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
  • Category
  • CategoryIOT_LAUNCHER

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

   
   
       
       
           
           
       
       
       
           
           
           
       
   

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

你可能感兴趣的文章
洛谷 P1411 树
查看>>
打字游戏--飞机大战
查看>>
文本输入框、密码输入框
查看>>
内联式css样式,直接写在现有的HTML标签中
查看>>
HackerRank - Bricks Game
查看>>
Expect 教程中文版
查看>>
libcurl 客户端实例
查看>>
由Node.js事件驱动模型引发的思考
查看>>
easyUI样式之easyui-switchbutton
查看>>
在raspberry的jessie版系统上安装opencv3.0
查看>>
codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
查看>>
maven笔记学习
查看>>
关于学习编程的一些看法
查看>>
oracle操作
查看>>
AngularJS $eval $parse
查看>>
electron 创建窗口2
查看>>
zookeeper
查看>>
MySql的四种事务隔离级别
查看>>
隐藏Nginx版本号的安全性与方法
查看>>
基础知识:页面div始终浮在浏览器顶部
查看>>