如何获取app 的包名和activity 名

如何获取app 的包名和activity 名,第1张

在Android中,应用程序的版本号是在AndroidManifestxml文件中进行配置的,而PackageInfo类则封装了从该配置文件中获取的所有信息,描述了包内容的整体信息,因此,可以使用PackageInfo对象的versionName属性获取应用的版本号。要怎么获取PackageInfo对象呢?可以通过PackageManager对象来获取。PackageManager是一个检索当前已安装在设备上的相关应用程序包的各种信息的类。PackageManager对象中的getPackageInfo方法可以获取PackageInfo对象,该方法需要传递两个参数:应用包名和条件。通常情况下,应用程序的包名可以通过Activity或Context(Activity继承自Context)的getPackageName()方法获取,而添加可以有很多设置,通常设置为0。最后是PackageManager对象的获取,Context对象提供了getPackageManager()方法来获取该对象。

原理:

通过查看AndroidManifestxml

方法:

可以通过如下方法获得:

1aapt

aapt dump xmltree apk路径 AndroidManifestxml > 输入的路径

2apktool 反编译

apktool d -f apk路径 输出的路径

3monkey---Android自带的工具

adb shell monkey --port 1080 -v -v

aapt即 Android Asset Packaging Tool

该工具在SDK/tools目录下,如果你没有设置环境变量,那需要进入该目录下才能运行aapt命令,如果设置了环境变量则可以在任何目录下运行aapt命令了。

1、列出压缩文件目录

aapt l[ist] [-v] [-a] file{zip,jar,apk}

参数:

-v:会以table的形式输出目录,table的表目有:Length、Method、Size、Ratio、Date、Time、CRC-32、Name。其中Method表示压缩形式,有Deflate和Stored两种,即该Zip目录采用的算法是压缩模式还是存储模式;Ratio表示压缩率。

-a:会详细输出所有目录的内容。

2、查看APK的相关信息

aapt d[ump] [--values] WHAT file{apk} [asset [asset ]]

badging Print the label and icon for the app declared in APK

permissions Print the permissions from the APK

resources Print the resource table from the APK

configurations Print the configurations in the APK

xmltree Print the compiled xmls in the given assets

xmlstrings Print the strings of the given compiled xml assets

1)、查看APK包的packageName、versionCode、applicationLabel、launcherActivity、permission等各种详细信息

aapt dump badging < fileapk>

2)、查看权限

aapt dump permissions <fileapk>

3)、查看资源列表

aapt dump resources <fileapk>

把查看信息保存到文件中去可以使用:

aapt dump resources <file_pathapk> > sodinotxt

4)、查看APK配置信息

aapt dump configurations <file_pathapk>

5)、查看指定APK的指定XML文件

aapt dump xmltree <file_pathapk> res/xml

以树形结构输出的xml信息。

aapt dump xmlstrings <file_pathapk> res/xml

输出xml文件中所有的字符串信息。

3、编译android资源

aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifestxml] \

[-0 extension [-0 extension ]] [-g tolerance] [-j jarfile] \

[--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \

[--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \

[--rename-manifest-package PACKAGE] \

[--rename-instrumentation-target-package PACKAGE] \

[--utf16] [--auto-add-overlay] \

[--max-res-version VAL] \

[-I base-package [-I base-package ]] \

[-A asset-source-dir] [-G class-list-file] [-P public-definitions-file

\

[-S resource-sources [-S resource-sources ]] \

[-F apk-file] [-J R-file-dir] \

[--product product1,product2,] \

[-c CONFIGS] [--preferred-configurations CONFIGS] \

[-o] \

[raw-files-dir [raw-files-dir] ]

Package the android resources It will read assets and resources that are

supplied with the -M -A -S or raw-files-dir arguments The -J -P -F and -R

options control which files are output

部分参数解释:

-f:如果编译出来的文件已经存在,强制覆盖;

-m:使生成的包的目录放在-J参数指定的目录;

-J:指定生成的RJava的输出目录;

-S:res文件夹路径;

-A:assert文件夹的路径;

-M:AndroidManifestxml的路径;

-l:某个版本平台的androidjar的路径;

-F:具体指定APK文件的输出

1)、将工程的资源编译出Rjava文件

aapt package –m –J <Rjava目录> -S <res目录> -l <androidjar目录> -M

<AndroidManifestxml目录>

2)、将工程的资源编译到一个包里

aapt package –f –S <res目录> -l <androidjar目录> -A <assert目录> -M

<AndroidManifestxml目录> -F <输出的包目录>

4、打包好的APK中移除文件

aapt r[emove] [-v] file{zip,jar,apk} file1 [file2 ]

5、添加文件到打包好的APK中

aapt a[dd] [-v] file{zip,jar,apk} file1 [file2 ]

6、显示aapt的版本

aapt v[ersion]

想着自动刷刷宝、抖音、火山。。。哦,确实有点贪财。但是不知道在写打开App的时候component部分怎么填写。例如打开刷宝:AppdevicestartActivity(component='comkuaishounebula/comyxcorpgifshowHomeActivity t4069')

网上找到了获取appPackage和appActivity的方法,来自于 >

以上就是关于如何获取app 的包名和activity 名全部的内容,包括:如何获取app 的包名和activity 名、怎样获取应用的包名和类名及解析aapt、获取appPackage和appActivity等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9622329.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存