我在Android下载二进制文件问题 和以编程方式在Android上安装应用程序的帮助下做到了这一点 .
我想立即进行自动更新和自动安装.它是本地的,所以它是非市场应用.
这是我的代码:
public void Update(String apkurl){
try {
URL url = new URL(apkurl);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();//till here, it works fine …Run Code Online (Sandbox Code Playgroud) 我试图默默安装apk到系统中.我的应用程序位于/ system/app并成功授予权限"android.permission.INSTALL_PACKAGES"
但是我找不到任何地方如何使用此权限.我试图将文件复制到/ data/app并没有成功.我也试过使用这段代码
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file:///sdcard/app.apk"),
"application/vnd.android.package-archive");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但是此代码打开标准安装对话框.如何在没有root的情况下以静默方式安装app android.permission.INSTALL_PACKAGES?
PS我正在编写一个应用程序,它会在第一次启动时将许多来自文件夹的apks安装到系统中(替换安装向导).我需要它来使固件更轻.
如果您认为我正在编写病毒:所有程序都安装在/ data/app中.权限Install_packages只能授予位于/ system/app中的系统级程序或使用系统密钥签名.所以病毒无法到达那里.
如上所述http://www.mail-archive.com/android-porting@googlegroups.com/msg06281.html应用程序如果具有install_packages权限,则可以进行静默安装.此外,您不需要Install_packages权限来安装软件包.另外还有http://www.androidzoom.com/android_applications/tools/silent-installer_wgqi.html