gpt4 book ai didi

运行外部代码/应用程序的 Android 应用程序?

转载 作者:行者123 更新时间:2023-11-30 04:50:50 24 4
gpt4 key购买 nike

我需要一个 Android 应用程序,它应该能够从网络(可能是 .apk 或 .jar)获取数据并从中启动“某些东西”。

如果它是一个“普通”类,则完全没有问题。这是我的加载器

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);


}
}

问题是我要执行的代码看起来很像一个应用程序,它应该有一个“简单”的 View 和一些交互。

我无法调用已下载类的“onCreate”方法。

我想我有三个街道:

  1. 我正在寻找一种静默安装应用程序然后运行它的方法(可能吗?);
  2. 在您的帮助下,我了解了如何在我自己的应用程序中初始化第二个“应用程序”(带有自己的 R 和所有东西);
  3. 我编写了我的主程序来从网络上获取数据并动态构建页面。

所以,我绝对需要你的帮助!

最佳答案

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.

肯定有符合此描述的东西应该有效。就我个人而言,我建议您只使用 HTML5,可能由 WebView 托管,因为 HTML 是一种用于动态生成 UI 的行之有效的解决方案(正如这个网页所说明的那样)。

关于运行外部代码/应用程序的 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3470862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com