9

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

Thanx Kaps

Smith
  • 93
  • 1
  • 1
  • 3
  • this should work for manifest too: http://stackoverflow.com/questions/3868768/extracting-android-apk-and-reading-contents-of-xml-file-in-res-layout – bigstones Apr 20 '11 at 10:42
  • I want to do this programatically, will this be still useful? – Smith Apr 20 '11 at 11:09

4 Answers4

20

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.

Albin
  • 4,090
  • 2
  • 26
  • 19
  • Great tip. Please make this an answer to: http://stackoverflow.com/questions/6547703/list-all-activities-within-an-apk-from-the-shell – scorpiodawg Oct 05 '12 at 20:05
10

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.

David Snabel-Caunt
  • 57,156
  • 12
  • 110
  • 132
0

其实不用得到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);
Neil
  • 52,766
  • 8
  • 57
  • 71
0

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

  • 1
    Are you sure that you need a decompiler? The manifest should be accessible and readable at the root of the apk file... – WarrenFaith Apr 20 '11 at 11:01
  • I want to do this programatically, can i access this tool from my Java code? – Smith Apr 20 '11 at 11:10
  • @WarrenFaith. Probably you're right, I just mentioned one possible solution. @kaps I see. If you want to do it programatiicaly, you can't use my solution. –  Apr 20 '11 at 11:40