admin 管理员组

文章数量: 1086019

1.请看代码。我这里给出一个下载apk的方法,这个方法需要传apk的下载地址

   private String appUrl; //应用升级地址
    private String appName="xxxxx"; //应用名称
    private String updateFile; //最新APK的路径

    private HttpURLConnection connection;
    private final int NEW_MESSAGE_ID = 0;

    /**
     * 下载更新APK文件
     *
     * @param appUrl    apk的下载地址
     * @return   自己定义的消息通知
     */
    private int downloadUpdateFile(final String appUrl) {
   
        try {
   

            //设置进度条操作
            URL url = new URL(appUrl);
            //打开和URL之间的连接
            connection = (HttpURLConnection) url.openConnection();
            //设置网络请求
            connection.setRequestMethod("GET");
            //开始读取服务器端数据,到了指定时间还没有读到数据,则报超时异常
            connection.setReadTimeout(50000);
            //要取得长度,要求http请求不要gzip压缩
            connection.setRequestProperty("Accept-Encoding", "identity"); // 添加这行代码

            //建立实际的连接
            connection.connect();
            //这里开启一个子线程,如果要更新UI,请切换到主线程
            new Thread(new Runnable

本文标签: 下载地址 只需要 版本 功能 Android