我在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) 最近我要开展一个项目,其中的要求很奇怪.我被要求开发一个应用程序,不会上传到任何市场,如Playstore或任何其他Android应用程序商店.它将简单地上传到云端,以便在用户之间分发APK.
在用户设备上安装应用程序后,当发布新版本时,将通知用户(通知不下载新版本并重新安装,但授予权限和更新).在用户授予权限后,应用程序将会更新.没有市场帮助,最好的方法是什么?
我的想法:
有没有更明智的方法来实现我想要实现的目标?