mercredi 26 août 2015

How to invoke a GUI Class from external apk in android

I have loaded a external apk through DexClassLoader. in a method will be invoked has a GUI load from .xml layout. But i can not view this GUI (from external apk) through invoke method !!

In conclusion, I want to load a GUI from an external APK file through invoke method. Please help me !! p/s: sorry about my english!

final File _optimizedDexOutputPath = getDir("outdex", Context.MODE_PRIVATE);
    String _className;
    String _methodToInvoke;
    String _apkfilePath;


    HashMap<String, String> hmData;

    //Prepare
    hmData = preWorkflow();
    _className = hmData.get("className");
    _apkfilePath = hmData.get("apkfilePath");
    _methodToInvoke = hmData.get("methodToInvoke");


    DexClassLoader dLoader = new DexClassLoader(_apkfilePath,
            _optimizedDexOutputPath.getAbsolutePath(),
            null, ClassLoader.getSystemClassLoader().getParent());
    try {
        Class<?> loadedClass = dLoader.loadClass(_className);
        Object obj = (Object) loadedClass.newInstance();

        Method m = loadedClass.getDeclaredMethod(_methodToInvoke);
        m.invoke(obj);

    } catch (IllegalAccessException e) {
        e.getCause().printStackTrace();
    } catch (InvocationTargetException e) {
        e.getCause().printStackTrace();
    }catch (NullPointerException e){
       e.getCause().printStackTrace();
    }  catch(Exception ex) {
        ex.printStackTrace();
    }





Aucun commentaire:

Enregistrer un commentaire