XNVersionService.java
2.23 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.metroapp.utils;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.IBinder;
import com.alibaba.fastjson.JSON;
import com.allenliu.versionchecklib.core.AVersionService;
import com.metroapp.bean.UpdateInfo;
public class XNVersionService extends AVersionService {
public XNVersionService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
private PackageInfo getPackageInfo() {
PackageInfo pinfo = null;
try {
pinfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException var3) {
var3.printStackTrace();
}
return pinfo;
}
@Override
public void onResponses(AVersionService service, String response) {
try {
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(response);
UpdateInfo updateInfo = new UpdateInfo();
updateInfo.setApkUrl(jsonObject.getString("apkUrl"));
updateInfo.setAppName(jsonObject.getString("appName"));
updateInfo.setVersionCode(jsonObject.getString("versionCode"));
updateInfo.setVersionName(jsonObject.getString("versionName"));
updateInfo.setChangeLog(jsonObject.getString("changeLog"));
updateInfo.setUpdateTips(jsonObject.getString("updateTips"));
if(Integer.parseInt(updateInfo.getVersionCode()) > this.getPackageInfo().versionCode) {
service.showVersionDialog(updateInfo.getApkUrl(), "检测到新版本", updateInfo.getChangeLog());
}
}catch (Exception e){
//不做处理
e.printStackTrace();
}
//可以在判断版本之后在设置是否强制更新或者VersionParams
//eg
// versionParams.isForceUpdate=true;
// or
// showVersionDialog("http://down1.uc.cn/down2/zxl107821.uc/miaokun1/UCBrowser_V11.5.8.945_android_pf145_bi800_(Build170627172528).apk", "检测到新版本", getString(R.string.updatecontent));
}
}