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.