how to start an activity in an apk without installation?
I have a demand like this ,i wanna start an activity in an apk files,but i don't want to invoke installation.just load the classes and resources in apk directly.
here is my code but the activity is not initialized correctly.
DexClassLoader dLoader = new DexClassLoader( APK_PATH,"/mnt/sdcard",null, ClassLoader.getSystemClassLoader().getParent());
PackageInfo pInfo;
pInfo = getPackageManager().getPackageArchiveInfo(APK_PATH, 1);
if ((pInfo.activities != null) && (pInfo.activities.length > 0))
{
clientClass = dLoader.loadClass(pInfo.activities[0].name);
clientInstance = clientClass.getConstructor(new Class[0]).newInstance(new Object[0]);
Class[] tempClasses = new Class[1];
tempClas开发者_StackOverflowses[0] = Bundle.class;
Method onCreateMethod = clientClass.getDeclaredMethod("onCreate", tempClasses);
onCreateMethod.setAccessible(true);
Object[] tempObjects = new Object[1];
tempObjects[0] = new Bundle();
onCreateMethod.invoke(clientInstance, tempObjects);
}
can someone help me ? I'll very appreciate.
You can't. Your code is also broken, doing things like having the absolute path "/mnt/sdcard" in it.
Fortunately, this is not possible.
精彩评论