Android Question ClassEnum

Andrei E

Member
Licensed User
Hi devs
Can anyone tell me how to resolve all classes in diffirent package?
Here is java code to resolve but I don't know how to use it
B4X:
#If JAVA
import java.util.ArrayList;
import java.io.File;

public static Class[] getClasses(String pckgname) throws ClassNotFoundException { 
    ArrayList classes=new ArrayList(); 
    File directory=null; 
    try { 
        directory=new File(Thread.currentThread().getContextClassLoader().getResource('/'+pckgname.replace('.', '/')).getFile()); 
    } catch(NullPointerException x) { 
        throw new ClassNotFoundException(pckgname+" does not appear to be a valid package"); 
    } 
    if(directory.exists()) { 
        String[] files=directory.list(); 
        for(int i=0; i<files.length; i++) { 
            if(files[i].endsWith(".class")) { 
                classes.add(Class.forName(pckgname+'.'+files[i].substring(0, files[i].length()-6))); 
            } 
        }
    } else { 
        throw new ClassNotFoundException(pckgname+" does not appear to be a valid package"); 
    } 
    Class[] classesA=new Class[classes.size()]; 
    classes.toArray(classesA); 
    return classesA; 
}
#End If
Like that or so:
B4X:
Dim jo As JavaObject
jo.InitializeStatic(?)
Dim Classes as List = jo.RunMethod("getClasses", Array As String("android.telephony.TelephonyManager"))
Thanks in advance
 

stevel05

Expert
Licensed User
Jo = Me

but android.telephony.TelephonyManager is not a package, it's a class.
 

Andrei E

Member
Licensed User
Thanks stevel05
Right, my mistake, I did mean class, not DexClassLoader
Any exaple of my code can be or not?
 

stevel05

Expert
Licensed User
At first glance it looks like the Java code is accessing a file system directly, which probably won't work with Android. Perhaps you can find an example of Android code to do what you want.
 
Top