从 Android 中的 apk 文件中读取 Activity 名称 [英] Reading Activity names from apk file in Android

查看:36
本文介绍了从 Android 中的 apk 文件中读取 Activity 名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个 android apk 文件中提取所有活动名称.知道怎么可能做到吗?

I want to extract all the activities names from an android apk file. Any idea how possibly it can be done?

谢谢卡普斯

推荐答案

可以使用PackageManager方法getPackageArchiveInfo 从 APK 文件中检索信息.假设您的 APK 位于 SD 卡的根目录中,您可以使用以下代码:

You can use the PackageManager method getPackageArchiveInfo to retrieve the information from an APK file. Assuming your APK lives in the root of your SD card, you can use this code:

    String apkPath = Environment.getExternalStorageDirectory().getAbsolutePath() 
                   + "/MyApp.apk";
    PackageManager pm = getPackageManager();

    PackageInfo info = pm.getPackageArchiveInfo(apkPath, 
                           PackageManager.GET_ACTIVITIES);
    //Log.i("ActivityInfo", "Package name is " + info.packageName);

    for (android.content.pm.ActivityInfo a : info.activities) {
        Log.i("ActivityInfo", a.name);
    }

您可以在 ActivityInfo 和 PackageInfo 对象中找到大量其他信息.

There is plenty of additional information you can find in the ActivityInfo and PackageInfo objects.

这篇关于从 Android 中的 apk 文件中读取 Activity 名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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