Created
December 5, 2018 07:11
-
-
Save flyfire/4bf652ab61682dc0eeb319613c3399ae to your computer and use it in GitHub Desktop.
[得到同一包名下的所有Class] #DexFile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun getClassesNameListInPackage(packageName: String, context: Context): List<String> { | |
| val realPackageName = "${context.packageName}.$packageName" | |
| val df = DexFile(context.packageCodePath) | |
| val enumration = df.entries() | |
| val list = mutableListOf<String>() | |
| while (enumration.hasMoreElements()) { | |
| val className = enumration.nextElement() | |
| if (className.contains(realPackageName)) { | |
| list.add(className) | |
| } | |
| } | |
| return list | |
| } | |
| fun getClassesInPackage(packageName: String, context: Context) | |
| = getClassesNameListInPackage(packageName, context).mapNotNull { Class.forName(it) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment