Android 从 adb 获取包的可启动活动名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12698814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:28:07  来源:igfitidea点击:

get launchable activity name of package from adb

androidadb

提问by fruitJuice

Is there a way to get the launchable activity for a package from using adb? For an unroot phone (i.e. without having the pull the apk from /data/appdirectory and inspect with appt).

有没有办法从使用中获取包的可启动活动adb?对于 unroot 手机(即没有从/data/app目录中提取 apk并使用 进行检查appt)。

I tried dumpsys, but it does not include information on default launchable activity.

我尝试了 dumpsys,但它不包含有关默认可启动活动的信息。

Thanks

谢谢

回答by kabuko

You don't need root to pull the apk files from /data/app. Sure, you might not have permissions to list the contents of that directory, but you can find the file locations of APKs with:

您不需要 root 即可从 .apk 中提取 apk 文件/data/app。当然,您可能没有列出该目录内容的权限,但您可以通过以下方式找到 APK 的文件位置:

adb shell pm list packages -f

Then you can use adb pull:

然后你可以使用adb pull

adb pull <APK path from previous command>

and then aaptto get the information you want:

然后aapt获取您想要的信息:

aapt dump badging <pulledfile.apk>

回答by friederbluemle

$ adb shell pm dump PACKAGE_NAME | grep -A 1 MAIN

回答by Alex P.

Since Android 7.0 you can use adb shell cmd package resolve-activitycommand to get the default activity of an installed app like this:

从 Android 7.0 开始,您可以使用adb shell cmd package resolve-activity命令来获取已安装应用的默认活动,如下所示:

adb shell "cmd package resolve-activity --brief com.google.android.calculator | tail -n 1"
com.google.android.calculator/com.android.calculator2.Calculator

回答by PradyJord

I didn't find it listed so updating the list.

我没有找到它,所以更新列表。

You need to have the apk installed and running in front on your phone for this solution:

您需要在手机上安装并运行 apk 才能使用此解决方案

Windows CMD line:

Windows CMD 行:

adb shell dumpsys window windows | findstr <any unique string from your pkg Name>

adb shell dumpsys window windows | findstr <any unique string from your pkg Name>

Linux Terminal:

Linux终端:

adb shell dumpsys window windows | grep -i <any unique string from your Pkg Name>

adb shell dumpsys window windows | grep -i <any unique string from your Pkg Name>

OUTPUT for Calculator package would be:

计算器包的输出将是:

Window #7 Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}:

    mOwnerUid=10036 mShowToOwnerOnly=true package=com.android.calculator2 appop=NONE

    mToken=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}

    mRootToken=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}

    mAppToken=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}

    WindowStateAnimator{3e160d22 com.android.calculator2/com.android.calculator2.Calculator}:

      mSurface=Surface(name=com.android.calculator2/com.android.calculator2.Calculator)

  mCurrentFocus=Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}

  mFocusedApp=AppWindowToken{29a4bed4 token=Token{2f850b1a ActivityRecord{eefe5c5 u0 com.android.calculator2/.Calculator t322}}}

Main part is, First Line:

主要部分是,第一行

Window #7 Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}:

Window #7 Window{39ced4b1 u0 com.android.calculator2/com.android.calculator2.Calculator}:

First part of the output is package name:

输出的第一部分是包名:

com.android.calculator2

com.android.calculator2

Second Part of output (which is after /) can be two things, in our case its:

输出的第二部分(在 之后/)可以是两件事,在我们的例子中是:

com.android.calculator2.Calculator

com.android.calculator2.Calculator

  1. <PKg name>.<activity name>= <com.android.calculator2>.<Calculator>

    so .Calculatoris our activity

  2. If second part is entirely different from Package name and doesn't seem to contain pkg name which was before /in out output, then entire second part can be used as main activity.

  1. <PKg name>.<activity name>= <com.android.calculator2>.<Calculator>

    .Calculator我们的活动也是如此

  2. 如果第二部分与包名称完全不同,并且似乎不包含/输入输出之前的 pkg 名称,则整个第二部分可以用作主要活动。

回答by zfu

#!/bin/bash
#file getActivity.sh
package_name=
#launch app by package name
adb shell monkey -p ${package_name} -c android.intent.category.LAUNCHER 1;
sleep 1;
#get Activity name
adb shell logcat -d | grep 'START u0' | tail -n 1 | sed 's/.*cmp=\(.*\)} .*//g'


sample:

样本:

getActivity.sh com.tencent.mm
com.tencent.mm/.ui.LauncherUI

回答by Rameshwar

Here is another way to find out apps package name and launcher activity.

这是找出应用程序包名称和启动器活动的另一种方法。

Step1: Start "adb logcat" in command prompt.

步骤 1:在命令提示符下启动“adb logcat”。

Step2: Open the app (either in emulator or real device) enter image description here

Step2:打开应用程序(模拟器或真机) 在此处输入图片说明

回答by Pawan Rajen

You can also use ddms for logcat logs where just giving search of the app name you will all info but you have to select Info instead of verbose or other options. check this below image.

您还可以将 ddms 用于 logcat 日志,其中只需搜索应用程序名称,您将获得所有信息,但您必须选择信息而不是详细或其他选项。检查下图。

enter image description here

在此处输入图片说明

回答by krrish

Launch your app and keep it in foreground.

启动您的应用程序并将其保持在前台。

Run the below command:

运行以下命令:

adb shell dumpsys window windows | find "mcurrentfocus"

adb shell dumpsys 窗口 windows | 找到“mcurrentfocus”