Webからデータ(おそらく.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」メソッドを呼び出すことができません。
私は3つの通りがあると思います:
- アプリケーションをサイレントインストールして実行する方法を探しています(可能ですか?)。
- あなたの助けを借りて、私は自分のアプリケーション内で2番目の「アプリケーション」を初期化する方法を理解しています(独自のRとすべてのものを使用)。
- Webからデータをフェッチし、ページを動的に構築するマスタープログラムを作成します。
だから、私は間違いなくあなたの助けが必要です!