Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.util.Enumeration;
import java.util.List;

import dalvik.system.DexFile;

public class Main {
    private static final String LOGTAG = "ClassUtils";

    public static void findClassesInApk(String apkPath, String packageName, List<String> classNames)
            throws IOException {

        DexFile dexFile = null;
        try {
            dexFile = new DexFile(apkPath);
            Enumeration<String> apkClassNames = dexFile.entries();
            while (apkClassNames.hasMoreElements()) {
                String className = apkClassNames.nextElement();

                if (className.startsWith(packageName) && isToplevelClass(className)) {
                    classNames.add(className);
                }
            }
        } catch (IOException e) {
            android.util.Log.w(LOGTAG, "Error finding classes at apk path: " + apkPath, e);
        }
    }

    private static boolean isToplevelClass(String fileName) {
        return fileName.indexOf('$') < 0;
    }
}