从Android的apk文件阅读活动名称名称、文件、Android、apk

2023-09-05 09:07:40 作者:姐不狂,姐拽

我想提取一个Android APK文件中的所有活动的名称。 任何想法怎么可能是可以做到的?

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

感谢名单 KAPS

推荐答案

您可以使用PackageManager方法getPackageArchiveInfo检索一个APK文件中的信息。假设你的APK生活在你的SD卡的根目录下,你可以使用这个code:

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.