Android Things引导意图

9

当我部署应用程序到Android Things后重新启动设备,应用程序没有启动。

是否有特定的意图来在启动时启动应用程序?

6个回答

17
如果您的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原来需要IOT_LAUNCHER,但现在已弃用)

然后您的应用程序将不会默认启动,而是会显示意图选择器对话框,并且系统会等待用户输入以选择要运行的应用程序。(无论是否实际连接了显示器都会发生这种情况。如果没有显示器,设备可能会似乎只是挂起。)

我在这里编写了一个脚本:https://gist.github.com/blundell/7c0c3bb17898b28fe8122b0dc230af50,该脚本将卸载具有上述意图过滤器的所有应用程序,以便您可以重新开始,并仅安装1个应用程序-因此此应用程序将在启动时启动。

script to uninstall example


使用最新版本的AndroidThings,意图选择器将不再显示,但问题可能仍会存在,因为其中一个已安装的应用程序被选中打开,而其他应用程序则未打开。


我发现一个名为IoTLauncher的进程决定使用启动器意图启动第一个活动:01-01 00:00:59.516 639-639/com.android.iotlauncher D/IoTLauncher: 发现2个具有启动器意图的活动 01-01 00:00:59.516 639-639/com.android.iotlauncher W/IoTLauncher: 找到多个具有启动器意图的应用程序。启动第一个找到的 01-01 00:00:59.624 639-639/com.android.iotlauncher I/IoTLauncher: 软件版本7.0 - remcoder
有没有办法恢复已删除的应用选择器功能 - 在开发时它实际上非常有用,而且在没有任何主屏幕的情况下也是如此。 - Carl Whalley
你自己编码应该很容易(不能 _恢复它_),你可以看看Launcher应用的源代码并使用包管理器查找应用程序,然后自己创建对话框。也许做这个会很有趣,也可能是浪费时间的大事。 :-) - Blundell

6

添加到 AndroidManifest.xml

开发者预览版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>

在开发者预览版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>

请查看2018年4月16日发布的Android Things RC版


首先,我假设像上面回答中的Blundell所解释的那样,并尝试使用这些过滤器删除所有应用程序,但这并没有帮助。按照您所写的更改意图过滤器后,应用程序在重新启动设备后成功启动。我正在AndroidThings 0.8上尝试这个,同时我已经更新到1.0.0。所以感谢你! - msamardzic

3
需要在AndroidManifest.xml中添加以下intent-filter:
<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>

3

你试过他们的演示应用吗?在编写自己的应用程序之前,请先尝试使用此链接。这应该可以正常工作。稍后再根据您的需要进行更改。

只需不要删除您代码中的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>

0

用户fishjd的答案,帮了我很多。如果那个方法不行,可以尝试使用adb删除应用程序,并重新安装它。

adb uninstall <packet>

0
为了在应用中支持Android Things,我们需要定义主入口点,以便系统可以在启动时自动启动。同时,为活动添加意图过滤器必须包含一个同时包括“CATEGORY_DEFAULT”和“IOT_LAUNCHER”的意图过滤器。
<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>

在 Android 应用程序中检查 Home activity support,了解 Android Things。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接