从服务器监听更新和安装

Mai*_*dul 7 android updates android-intent apk

  1. 首先,我有一个服务器.我检查服务器是否有任何new apk文件我下载这个并尝试安装.
  2. 如果服务器有,new version of apk file那么我想更新我的.apk文件.
  3. 我想在没有用户交互的情况下安装/更新.这可能吗?
  4. 如果需要用户交互,那么我该如何安装/更新.apk文件.

我对此并不了解更多.

 Intent intent = new Intent(Intent.ACTION_VIEW);
             intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "jarviz.apk")), "application/vnd.android.package-archive");
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Run Code Online (Sandbox Code Playgroud)

但这不起作用.我在调试时看不到任何错误,但它没有安装.我怎么能这样做.对于糟糕的英语.

Mai*_*dul 5

我用这种方式解决了这个问题.

String vsName=Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/";
File file = new File(vsName, "jarviz.apk");
System.out.println(":"+file);
Intent install=new Intent(Intent.ACTION_VIEW);
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(install);
Run Code Online (Sandbox Code Playgroud)