Reading Activity names from apk file in Android

*爱你&永不变心* 提交于 2019-12-18 13:17:11

问题


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

Thanx Kaps


回答1:


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);
    }

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




回答2:


If you just want to list them from the command line you can use

aapt dump xmltree <apk-file> AndroidManifest.xml

The format is a bit perplexing at first, but all the info is there.

You need the Android SDK installed to do this, of course.




回答3:


You could use a decompiler like Dedexer and then you can take a look at the manifest.




回答4:


其实不用得到apk的路径,直接在activity内调用

(English translation) You don't have to use the full path to the APK, just call the following directly from inside an Activity.

PackageManager manager = getPackageManager();
PackageInfo packageInfo = manager.getPackageInfo("your package name", PackageManager.GET_UNINSTALLED_PACKAGES);


来源:https://stackoverflow.com/questions/5728903/reading-activity-names-from-apk-file-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!