集成热更,热更逻辑编写

This commit is contained in:
huangzhuanghua
2016-05-11 11:10:46 +08:00
parent f394fdacdd
commit cb6e9fd43f
18 changed files with 577 additions and 580 deletions

View File

@ -436,6 +436,60 @@ public class MainActivity extends BaseFragmentActivity implements
DataCollectionManager.upsert(MainActivity.this, "user", map);
}
}, 1000);
//检查是否存在更新的dex包
// checkHotfix();
}
private void checkHotfix() {
String version = PackageUtils.getVersion(getApplicationContext());
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
String url = "http://api.ghzhushou.com/v1d45/hotfix?channel=" + TD_CHANNEL_ID + "&version=" + version;
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Utils.log("hotfix = " + response.toString());
try {
for (int i = 0; i < response.length(); i++) {
JSONObject jsonObject = response.getJSONObject(i);
String clazz = jsonObject.getString("class");
final String url = jsonObject.getString("url");
String fileName = url.substring(url.lastIndexOf("/"));
File directory = new File(getFilesDir().getAbsolutePath() + File.separator + "hotfix");
if (!directory.exists() || !directory.isDirectory()) {
directory.mkdirs();
}
File file = new File(directory.getAbsolutePath() + File.separator + fileName);
if (file.exists()) {
break;
}
//下载文件
final String savePath = file.getAbsolutePath();
new Thread(){
@Override
public void run() {
try {
FileUtils.downloadFile(url, savePath);
} catch (IOException e) {
e.printStackTrace();
}
Utils.log(savePath + " download success");
}
}.start();
//存储class
sp.edit().putString(file.getName(),clazz).apply();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Utils.log("hotfix = " + error.toString());
}
});
AppController.addToRequestQueue(request, MainActivity.class);
}
// 获取免责声明