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 android.content.Context;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import dalvik.system.DexFile;

public class Main {

    public static List<String> getPackageAllClassName(Context context, String packageName) throws IOException {
        String sourcePath = context.getApplicationInfo().sourceDir;
        List<String> paths = new ArrayList<>();

        if (sourcePath != null) {
            DexFile dexfile = new DexFile(sourcePath);
            Enumeration<String> entries = dexfile.entries();

            while (entries.hasMoreElements()) {
                String element = entries.nextElement();
                if (element.contains(packageName)) {
                    paths.add(element);
                }
            }
        }

        return paths;
    }
}