我需要一個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