0

how are you all? I hope that well, my little problem, or rather confusion, is as I already mentioned in the question, if it is possible to run an application from your apk with some methods already mentioned or with others that you know.

Why my doubt? My question is why I saw in my research references about the methods already mentioned and codes that I have implemented in mine but does not give effect in reality does nothing is:

final String apkFile ="storage/sdcard0/Mostrador_1.0.apk";
String className = "com.example.mostrador";
String methodToInvoke = "add"; 
final File optimizedDexOutputPath = getDir("outdex", 0);

DexClassLoader dLoader = new DexClassLoader(apkFile,optimizedDexOutputPath.getAbsolutePath(),
        null,ClassLoader.getSystemClassLoader().getParent());

try {
    Class<?> loadedClass = dLoader.loadClass(className);
    Object obj = (Object)loadedClass.newInstance();
    int x =5;
    int y=6;
    Method m = loadedClass.getMethod(methodToInvoke, int.class, int.class);
    int z = (Integer) m.invoke(obj, y, x);              
    System.out.println("The sum of "+x+" and "+"y="+z);

} catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (InstantiationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

From the question: Android- Using DexClassLoader to load apk file

Why do I want to know? The reason is that I want to implement in my application the ability to use auxiliary applications without having to download and these will be selected by the user.

If you know something about the point or subject to discuss please comment.

Electronicappap
  • 67
  • 1
  • 1
  • 9

1 Answers1

0

U can research these open source project on github. They are different implements of dynamic loading apk at runtime.

1.AndroidDynamicLoader

2.dynamic-load-apk

3.DroidPlugin

4.DynamicAPK

Cobain
  • 186
  • 1
  • 8
  • Friend thank you very much for the very compromising content that I am studying, but you can not give me a hand also referring to this topic: It is possible to run an application that is in another directory. I explain all files that are saved when the apk file is installed I moved it to another folder the data files are the apk, the .dex file, the cache. Is there any way to force the Android machine to run Esa Application Or create a machine to run them. Thank you very much. – Electronicappap Dec 13 '16 at 15:58