a
554325746@qq.com
2019-12-25 603cb36a5123e46656b06a5deb8d7ac7ff81307f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.basic.security.utils;
 
public class UpdateApk {
    public static void getApk() {
        try {
//            System1.out.println("UpdateApk.getApk 开始下载");
//            String out = new Scanner(new URL(Constants.getApkUrl).openStream(), "UTF-8").useDelimiter("\\A").next();
//            Gson gson = new Gson();
//            Map map = gson.fromJson(out, Map.class);
//            if ("true".equals(map.get("hasNewVersion"))) {
//                String newApkName = (String) map.get("newApkName");
//                String newApkSize = (String) map.get("newApkSize");
//                String newApkNameUrl = Constants.getApkUrl.substring(0, Constants.getApkUrl.lastIndexOf("/")) + "/" + newApkName;
//                String dirName = Environment.getExternalStorageDirectory() + "/download/";
//                new File(dirName).mkdirs();
//                File downloadedFile = new File(dirName, newApkName);
//                org.apache.commons.io.FileUtils.copyURLToFile(new URL(newApkNameUrl), downloadedFile);
//                if (Integer.parseInt(newApkSize) == downloadedFile.length()) {
//                    if (Constants.useAlf) {
//                        DeviceControl.startInstallApk(
//                                BaseApplication.getApplication(),
//                                "com.basic.security",
//                                downloadedFile.getAbsolutePath(),
//                                true,
//                                true
//                        );
//                    }
//                }
//            }
//
//            System1.out.println("UpdateApk.getApk 安装完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}