我碰壁了。任何帮助,将不胜感激。我有一个应用程序,我想使用 DexClassLoader 加载另一个 apk 文件。
这是我的代码:
DexClassLoader dLoader = new DexClassLoader("/sdcard/download/test.apk","/sdcard/download",null,ClassLoader.getSystemClassLoader().getParent());
Class calledClass = dLoader.loadClass("com.test.classname");
Intent it=new Intent(this, calledClass);
it.setClassName("com.test", "com.test.classname");
startActivity(it);
现在我已经安装了 test.apk 所以当我运行上面的代码时
工作正常并启动了该应用程序。不过我希望能够
在没有安装 test.apk 的情况下运行它(因为这会
击败应用程序的整个要点)。所以我卸载了它并
当我再次运行我的应用程序时,出现此错误:
android.content.ActivityNotFoundException: Unable to find explicit
activity class {com.test/com.test.classname}; have you declared this
activity in your AndroidManifest.xml.
所以我在这里有点困惑。此活动在清单中声明
我尝试运行的 apk 的名称。我无法在我的应用程序中声明它
显现。有任何想法吗?
谢谢,
克雷格
尝试使用 Android 的路径类加载器 https://developer.android.com/reference/dalvik/system/PathClassLoader.html:
String packagePath = "com.mypackage";
String classPath = "com.mypackage.ExternalClass";
String apkName = null;
try {
apkName = getPackageManager().getApplicationInfo(packagePath,0).sourceDir;
} catch (PackageManager.NameNotFoundException e) {
// catch this
}
// add path to apk that contains classes you wish to load
String extraApkPath = apkName + ":/path/to/extraLib.apk"
PathClassLoader pathClassLoader = new dalvik.system.PathClassLoader(
apkName,
ClassLoader.getSystemClassLoader());
try {
Class<?> handler = Class.forName(classPath, true, pathClassLoader);
} catch (ClassNotFoundException e) {
// catch this
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)