Android Question ClassEnum

Discussion in 'Android Questions' started by Andrei E, Mar 3, 2015.

  1. Andrei E

    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
    Code:
    #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:
    Code:
    Dim jo As JavaObject
    jo.InitializeStatic(?)
    Dim Classes as List = jo.RunMethod("getClasses"Array As String("android.telephony.TelephonyManager"))
    Thanks in advance
     
  2. stevel05

    stevel05 Expert Licensed User

    Jo = Me

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

    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?
     
  4. stevel05

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice