gpt4 book ai didi

android - 如何使用终端运行特定的 Android 应用程序?

转载 作者:IT王子 更新时间:2023-10-28 23:59:07 25 4
gpt4 key购买 nike

我已经安装了 Eclipse 和 Android SDK。一切正常。

我想安装一个 .apk 文件,所以我已经按照说明进行操作。但问题是,当我启动模拟器时,它不会自动运行我的应用程序。

终端中是否有允许我运行我要求的特定应用程序的命令?

最佳答案

使用 cmd activity start-activity(或替代的 am start)命令,它是 ActivityManager 的命令行界面.使用 am 启动 Activity ,如本帮助所示:

$ adb shell am
usage: am [start|instrument]
am start [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e <EXTRA_KEY> <EXTRA_VALUE> [-e <EXTRA_KEY> <EXTRA_VALUE> ...]
[-n <COMPONENT>] [-D] [<URI>]
...

例如,启动Contacts应用,假设你只知道包名而不知道Activity,你可以使用

$ pkg=com.google.android.contacts
$ comp=$(adb shell cmd package resolve-activity --brief -c android.intent.category.LAUNCHER $pkg | tail -1)
$ adb shell cmd activity start-activity $comp

或替代

$ adb shell am start -n $comp

另见 http://www.kandroid.org/online-pdk/guide/instrumentation_testing.html (可能是过时网址的副本:http://source.android.com/porting/instrumentation_testing.html)了解其他详细信息。

要终止您可以使用的应用程序

$ adb shell am kill com.google.android.contacts

或者更激烈的

$ adb shell am force-stop com.google.android.contacts

关于android - 如何使用终端运行特定的 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5494764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com