如何在 raspberry pi 3 上停止 android Things 应用程序并启动另一个 activity

how to stop android things app on raspberry pi 3 and start another activity

我从“https://developer.android.com/things/training/first-device/peripherals.html#handle_button_events”网站开发了我的第一个 android Things 应用程序。并将其部署在 raspberry pi 3(在 4.1 版上启动)。

在 raspberry pi 3 上轻松部署并给我闪烁的 Led。

但现在我不知道如何停止它,进行更改或开始其他项目。

它不停地闪烁,我不知道如何停止它。

在我的 android 工作室中,当我按下开始按钮时,它会显示连接的设备菜单,其中显示 raspberry pi 处于离线状态。 Like this

这个问题通过在CMD上执行'adb kill-server'命令解决。然后重新连接 raspberry pi 3。这样,离线标签就从 raspberry pi 3 模拟器中删除了。

发生这种情况是因为您已将该应用程序设置为默认启动应用程序。因此,它会在您打开 Android Thing 设备时立即加载。要解决这个问题,只需使用以下命令远程卸载当前软件包:

adb uninstall pkg-name

或使用以下命令并手动卸载它:

adb shell am start -a android.settings.SETTINGS

如果您处于调试阶段,最好转到清单文件并替换以下行:

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

与:

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

这样做会阻止将应用程序设置为默认启动应用程序

更新 1:IOT_LAUNCHER 已弃用,应替换为 HOME

Android Things OS 只有一个应用 "auto started"。因此,您的旧应用一直在启动。

您必须卸载旧应用程序以确保您的新应用程序是启动的。您可以使用

卸载它

adb uninstall your.package.name

或者,如果您安装了一些旧应用程序,您可以使用此脚本文件:

https://gist.github.com/blundell/7c0c3bb17898b28fe8122b0dc230af50

全部卸载(不需要知道包名!)


如果您的 Rasp Pi 被视为离线,您可以重新启动它(将其关闭再打开)。 :-)


脚本现已更新以查找:

 <category android:name="android.intent.category.HOME"/> 

在最新版本 (DP8)

中替换了 IOT_LAUNCHER

在 android 中你一次只能使用一个应用程序,所以使用 adb uninstall <installed-app-pkg-name> 然后开始将你的另一个项目安装到 Raspberry Pi 3. 同时删除 <category android:name="android.intent.category.IOT_LAUNCHER"/> 所以你的应用程序不会在启动时启动。

目前 <category android:name="android.intent.category.IOT_LAUNCHER"/> 在 android Things 稳定版 1.0 中已被 <category android:name="android.intent.category.HOME"/> 取代。

希望对您有所帮助。

您可以使用 adb 做很多事情,让我们看看一些 adb 命令,它们将帮助您进行 android 应用程序开发和测试。

假设您的设备有 IP 10.10.0.123

正在通过 adb 连接到您的设备

$ adb connect 10.10.0.123:5555

正在检查您的可用连接设备列表

$ adb devices

以上命令给出输出

List of devices attached 
10.10.0.123:5555    device

可以使用以下命令安装应用程序

$ adb -s 10.10.0.123:5555 install <path to your apk file>

示例:

$ adb -s 10.10.0.123:5555 install /home/shahbaz/Android-apps/example.apk

安装需要时间,具体取决于应用程序的大小,请耐心等待

以上安装命令输出

502 KB/s (15896167 bytes in 30.870s)
Success

卸载应用程序

为此你必须知道应用程序的包名

$ adb uninstall com.example.app

正在启动应用程序 首先连接到设备然后 运行 按照命令

$ adb shell 'am start $(cmd package resolve-activity --brief <package-name> | tail -n 1)'

例子

 $ adb shell 'am start $(cmd package resolve-activity --brief com.example.app | tail -n 1)'

这个命令的输出是这样的

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.app/.SpalshScreen }

关闭启动的应用程序

$ adb shell am force-stop <package-name>

示例

$ adb shell am force-stop com.example.app

其他操作可以进一步查看adb的man page

希望这对您有所帮助!