简体   繁体   English

Android Things意图启动

[英]Android Things intent for boot

When I reboot after deploying an application to Android Things the application doesn't start. 在将应用程序部署到Android Things后重新启动时,应用程序无法启动。

Is there a specific intent to start an application on boot? 是否有特定的意图在启动时启动应用程序?

If your Android Things device has multiple applications installed that all have this intent filter in the manifest: 如果您的Android Things设备安装多个 应用 程序 ,则清单中都有此意图过滤器:

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.HOME"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

( < DP8 used to need IOT_LAUNCHER that has been deprecated) (<DP8过去需要已弃用的IOT_LAUNCHER

Then your application will not start by default , instead the Intent Chooser dialog will be shown and the system will wait for user input to select which app to run. 然后默认情况下您的应用程序不会启动 ,而是会显示Intent Chooser对话框,系统将等待用户输入以选择要运行的应用程序。 (This happens wether or not you have an actual display plugged in. If you don't have a display it might appear as tho the device is just hanging.) (这种情况发生了或者你没有插入实际的显示器。如果你没有显示器,它可能会显示为设备只是悬挂。)

I wrote a script here: https://gist.github.com/blundell/7c0c3bb17898b28fe8122b0dc230af50 that will uninstall all applications that have the above Intent Filter so that you can start again and only have 1 application installed - therefore this application will start on boot. 我在这里编写了一个脚本: https//gist.github.com/blundell/7c0c3bb17898b28fe8122b0dc230af50 ,它将卸载所有具有上述Intent Filter的应用程序,以便您可以重新启动并且只安装了1个应用程序 - 因此该应用程序将在启动时启动。

脚本卸载示例


With the latest version of AndroidThings the IntentChooser will not be shown anymore, however the problem can persist as one of the apps installed is selected to open and the others do not. 使用最新版本的AndroidThings,IntentChooser将不会再显示,但是当安装的其中一个应用程序被选中打开而其他应用程序没有打开时,问题可能会持续存在。

Add to AndroidManifest.xml 添加到AndroidManifest.xml

Developer Preview 0.8 and greater (New Style) 开发者预览版0.8及更高版本(新款)

 <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.HOME"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> 

Before Developer Preview 0.8 (Old Style) 开发者预览版0.8之前(旧式)

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

See Android Things Release Candidate 16 April 2018 请参阅2018年4月16日的Android Things Release Candidate

The following intent-filter needs to be added to AndroidManifest.xml 需要将以下intent-filter添加到AndroidManifest.xml

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

Have you tried their demo app? 你试过他们的演示应用吗? Try out this first before writing your own app. 试试这写你自己的应用程序之前。 This should work as expected. 这应该按预期工作。 Later change as you want. 稍后随意改变。

Just don't remove this part from the AndroidManifest.xml of your code. 只是不要从代码的AndroidManifest.xml删除此部分。

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

To give Android Things support in app, We need to define main entry point for the system to automatically launch on boot. 要在应用程序中提供Android Things支持, 我们需要定义系统的主要入口点,以便在启动时自动启动。

While adding an intent filter for an activity must contain an intent filter that includes both CATEGORY_DEFAULT and IOT_LAUNCHER . 为活动添加intent过滤器时,必须包含一个包含CATEGORY_DEFAULTIOT_LAUNCHER的intent过滤器。

<application
android:label="@string/app_name">
<activity android:name=".HomeActivity">
    <!-- Launch activity as default from Android Studio -->
    <!-- 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. -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

    <!-- Add below intent filter which enable android things support for app -->
    <!-- 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>

Check Home activity support for Android Things in android app. 在Android应用中查看Android Things的Home活动支持

Answer from user fishjd, help me. 用户fishjd的回答,帮帮我。 If that didn't work, try deleting app using adb, and reinstalling it 如果这不起作用,请尝试使用adb删除应用,然后重新安装

adb uninstall <packet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM