我需要一个Android应用程序,它应该能够从网上获取数据(可能是.apk或.jar)并从中启动“某些东西”。运行外部代码/应用程序的Android应用程序?
如果这是一个“微不足道”的课程,那完全没有问题。这是我的装载机
package com.m31.android.urlload;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ClassLoader;
import java.net.URL;
import dalvik.system.PathClassLoader;
import dalvik.system.DexClassLoader;
public class Loader extends ClassLoader {
public Loader() throws IOException {
super(Loader.class.getClassLoader());
}
public Class loadClass(String className) throws ClassNotFoundException {
return findClass(className);
}
private String fetch_package(String url) throws IOException {
BufferedInputStream in = new BufferedInputStream(new URL(url).openStream());
FileOutputStream fos = new FileOutputStream("/mnt/sdcard/_plugins/plugin1.jar");
BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
int count;
while((count = in.read(data,0,1024)) > 0) {
bout.write(data,0,count);
}
bout.close();
in.close();
return "/mnt/sdcard/_plugins/plugin1.jar";
}
public Class findMyClass(String className, String url) throws IOException, ClassNotFoundException {
String path = fetch_package(url);
DexClassLoader pcl = new DexClassLoader(path, "/mnt/sdcard/_dex/", null, this);
return pcl.loadClass(className);
}
}
的问题是,我想执行看起来非常像一个应用程序,它应该有一个“简单”的观点,并在它的一些互动的代码。
我无法调用我下载的类的“onCreate”方法。
我想我已经三条街:
- 我找这静默安装应用程序的方法,然后运行它(?有没有可能);
- 在你的帮助下,我明白如何在我自己的内部初始化第二个“应用程序”(使用它自己的R和所有东西);
- 我写我的主程序从网上获取数据并动态构建页面。
所以,我绝对需要你的帮助!
那么devAppsDirect应用程序如何工作? https://play.google.com/store/apps/details?id=com.inappsquared.devappsdirect。我的意思是,我知道它不会安装apks,但它运行得非常好,而且它似乎存在于应用程序的内部存储器本身内。 – 2013-06-28 09:02:49