如何使用 .apk 文件运行(不仅是安装)Android 应用程序? [英] How to run (not only install) an android application using .apk file?

查看:34
本文介绍了如何使用 .apk 文件运行(不仅是安装)Android 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmd.exe 上是否有任何命令允许我使用该应用程序的 .apk 文件启动特定 android 应用程序的主要活动.请注意,我知道这个命令只安装一个 android 应用程序:

Is there any command on cmd.exe that would allow me to start the main activity of a particular android application using the .apk file of that application. Please note that I know this command which only installs an android application:

adb install myapp.apk

此命令只会将 myapp 安装到模拟器上,我必须从模拟器手动运行此应用程序(通过单击其图标).

This command will only install myapp onto the emulator and I have to manually run this application from the emulator (by performing single click on its icon).

我想要做的是使用一个不仅安装应用程序而且启动它的主要活动的命令(请注意,我只有它的 .apk 文件,所以我不知道什么是包名称或任何活动名称是).

What I want to do is use a command which not only installs the application but also starts its main activity (please note that I have only its .apk file so I don't know what the package name or any activity name is).

推荐答案

您无法一次性安装和运行 - 但您当然可以使用 adb 来启动您已安装的应用程序.使用 adb shell am start 来触发一个意图——不过你需要为你的应用程序使用正确的意图.几个例子:

You can't install and run in one go - but you can certainly use adb to start your already installed application. Use adb shell am start to fire an intent - you will need to use the correct intent for your application though. A couple of examples:

adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings 

将启动设置,并且

adb shell am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity 

将启动浏览器.如果要将浏览器指向特定页面,请执行此操作

will launch the Browser. If you want to point the Browser at a particular page, do this

adb shell am start -a android.intent.action.VIEW -n com.android.browser/.BrowserActivity http://www.google.co.uk

如果您不知道 APK 中活动的名称,请执行此操作

If you don't know the name of the activities in the APK, then do this

aapt d xmltree <path to apk> AndroidManifest.xml

输出内容将包括这样的部分:

the output content will includes a section like this:

   E: activity (line=32)
    A: android:theme(0x01010000)=@0x7f080000
    A: android:label(0x01010001)=@0x7f070000
    A: android:name(0x01010003)="com.anonymous.MainWindow"
    A: android:launchMode(0x0101001d)=(type 0x10)0x3
    A: android:screenOrientation(0x0101001e)=(type 0x10)0x1
    A: android:configChanges(0x0101001f)=(type 0x11)0x80
    E: intent-filter (line=33)
      E: action (line=34)
        A: android:name(0x01010003)="android.intent.action.MAIN"
        XE: (line=34)

这会告诉您主要活动的名称(MainWindow),您现在可以运行

That tells you the name of the main activity (MainWindow), and you can now run

adb shell am start -a android.intent.action.MAIN -n com.anonymous/.MainWindow

这篇关于如何使用 .apk 文件运行(不仅是安装)Android 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆