从我的网站在Android应用程序安装更新 [英] Install update in android app from my website

查看:108
本文介绍了从我的网站在Android应用程序安装更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前我的Web服务器没有在Android Market检查在后台的应用程序版本,每24小时一次。如果有可用更新,它提示用户下载新的apk。

I am currently checking the application version in background every 24 hours once in my web server not in android market. If update available that it prompt the user to download the new apk.

Uri uri = Uri.parse(downloadURL);
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);

以上code。打开浏览器用户和开始下载。

The above code open the user browser and start downloading.

我想不用打开浏览器,我需要下载apk文件或我需要直接安装最新的APK而无需打开和其他应用程序(如浏览器)

I want without opening the browser i need to download the apk file or i need to install the latest apk directly without opening and other application (like browser)

推荐答案

做这样的事情。

//首先你需要下载apk文件。

// First you need to download apk file.

    String extStorageDirectory =        Environment.getExternalStorageDirectory().toString();
        File folder = new File(extStorageDirectory, "APPS");
        folder.mkdir();
        File file = new File(folder, "AnyName."+"apk");
        try {
                file.createNewFile();
        } catch (IOException e1) {
                e1.printStackTrace();
        }
        /**
         * APKURL is your apk file url(server url)
         */
         DownloadFile("APKURL", file);

//将DownloadFile功能

// the DownloadFile function is

      public  void DownloadFile(String fileURL, File directory) {
       try {

            FileOutputStream f = new FileOutputStream(directory);
            URL u = new URL(fileURL);
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");
            //c.setDoOutput(true);
            c.connect();
            InputStream in = c.getInputStream();
            byte[] buffer = new byte[1024];
            int len1 = 0;
            while ((len1 = in.read(buffer)) > 0) {
                    f.write(buffer, 0, len1);
            }
            f.close();
    } catch (Exception e) {
        System.out.println("exception in DownloadFile: --------"+e.toString());
            e.printStackTrace();
    }

和下载apk文件后写这篇code

and after downloading the apk file write this code

       Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new   File(Environment.getExternalStorageDirectory() + "/APPS/" + "AnyName.apk")), "application/vnd.android.package-archive");
            startActivity(intent);

//并在清单赋予权限

// and give permission in manifest

     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

它可以帮助你,我用这对同您的需要。

it might help you, i used this for same as your need.

这篇关于从我的网站在Android应用程序安装更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆