更新的Andr​​oid应用程序(不包括谷歌播放)不包括、应用程序、Andr、oid

由网友(阳光快乐小男神)分享简介:我写的应用程序的Beta版本。这将可以通过网络下载(我不会把它发布到播放市场)。是否有可能更新不玩市场这个应用程序时,新版本将被释放?I wrote a Beta version of the application. It will be available for download through the web...

我写的应用程序的Beta版本。这将可以通过网络下载(我不会把它发布到播放市场)。是否有可能更新不玩市场这个应用程序时,新版本将被释放?

I wrote a Beta version of the application. It will be available for download through the web (I will not publish it to the Play Market). Is it possible to update this application without Play Market when the new version will be released?

推荐答案

当然可以。您将需要建立一个机制,但是,你的应用程序给家里打电话到服务器,看看是否有应用程序的更新版本,如果有,它拉下来,并安装它。一旦你已经确定你确实需要下拉更新,你可以做到这一点类似这个的AsyncTask:

Absolutely. You will need to build a mechanism, though, for your app to call home to the server, find out if there's a newer version of the app, and if there is, pull it down and install it. Once you've determined that you do need to pull down an update, you can do that with something similar to this 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);
}
阅读全文

相关推荐

最新文章