1

I have a simple android apk which has one activity and other classes with simple UI(two button, one text layout), I generated that as a apk and now I want to load that using dex class loader in a new android app and starts the activity of the apk from the new app.

I wrote a simple class loader but I dont know how to starts a activity of that apk, below is code written for loading the class,

please let me know 1. how to starts the activity of the apk? 2. how to load all the class of apk ?

final String apkFile =Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/Offloadme.apk";
String activtyName= "com.example.test.MainActivity";

final File optimizedDexOutputPath = getDir("outdex", 0);

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

try {
     //How to load all the class of that apk
     // How to call the activity


} 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();
}
scoder
  • 2,451
  • 4
  • 30
  • 70
  • 1
    The technique that you describe will cause your app to be rejected by the Play Store, if that is how you were planning on distributing this app. – CommonsWare Feb 23 '18 at 17:32
  • I want to try out this for some experimentation and if that works I will distribute only my mine app, the app which has to be loaded will be downloaded from external store.. – scoder Feb 23 '18 at 18:04

0 Answers0