更新Android应用(无需Google Play)

我写了一个testing版的应用程序。 它可以通过networking下载(我不会将它发布到Play市场)。 当新版本发布时,是否有可能在没有Play Market的情况下更新此应用程序?

绝对。 但是,您需要构build一个机制,让您的应用程序调用服务器,查看是否有更新版本的应用程序,如果有,请将其拉​​下并安装。 一旦你确定你需要下载一个更新,你可以用类似于这个AsyncTask来做到这一点:

protected String doInBackground(String... sUrl) { String path = "/sdcard/YourApp.apk"; try { URL url = new URL(sUrl[0]); URLConnection connection = url.openConnection(); connection.connect(); int fileLength = connection.getContentLength(); // download the file InputStream input = new BufferedInputStream(url.openStream()); OutputStream output = new FileOutputStream(path); byte data[] = new byte[1024]; long total = 0; int count; while ((count = input.read(data)) != -1) { total += count; publishProgress((int) (total * 100 / fileLength)); output.write(data, 0, count); } output.flush(); output.close(); input.close(); } catch (Exception e) { Log.e("YourApp", "Well that didn't work out so well..."); Log.e("YourApp", e.getMessage()); } return path; } // begin the installation by opening the resulting file @Override protected void onPostExecute(String path) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive" ); Log.d("Lofting", "About to install new .apk"); this.context.startActivity(i); } 

是的,这是可能的,大致可以这样做:

  1. 获取当前应用程序的versionCode

     PackageInfo packageInfo = getPackageManager().getPackageInfo(context.getPackageName(), 0); int curVersionCode = packageInfo.versionCode; 
  2. 有一个服务器,你主持的apk文件,并创build一个简单的纯文件,只包含一个整数,代表最新的应用程序版本代码。

  3. 当应用程序启动(或者当你想检查更新时),从服务器(即通过HTTP请求)检索最新的versionCode,并将其与当前的应用程序版本进行比较。

  4. 如果有新版本,请下载apk并安装(会提示用户对话)。

编辑:

你可以使用@Blumer的代码。

但是请记住,用户必须在其设置中启用“允许安装非市场应用程序/未知来源”。

仅供参考,我刚刚阅读了这个在http://blog.vivekpanyam.com/evolve-seamlessly-deploy-android-apps-to-users/?hn

Evolve是Android开发人员的图书馆,可让他们部署应用程序的新版本,而无需通过Google Play或要求用户下载更新。 它通过使用reflection和dynamic字节码生成来“欺骗”Android来运行新代码。

虽然它的alpha,但似乎可以通过很多的箍。 我怀疑它是否值得除了恶意软件..