Hi all, guys.
This is my target:
I need an Android application which should be able to fetch data from the web (maybe an .apk or a .jar) and launch "something" from it.
If it's a "trivial" class there's no problem at all. This is my Loader
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);
}
}
The problem is that the code I want to execute looks very like an application, which should have a "simple" view and some interaction on it.
I'm not able to invoke the "onCreate" method of my downloaded class.
I guess I've three streets:
- I look for a method which silently install the application and then runs it (is it possible?);
- With your help, I understand how to initialize a second "application" inside my own one (with its own R and all stuff);
- I write my master program to fetch data from the web and construct pages dinamically.
So, I definitely need your help! Thanks in advice!