Comments (17)
我也出现这个问题,6.0手机
from update.
是因为解析得到的 UpdateInfo 为 null
如果设置了UpdateAgent.InfoParser 请确保返回值不为 null
from update.
在4.4手机上正常,6.0就是这样了
from update.
看代码,只有解析返回的 UpdateInfo 为 null时才会提示 CHECK_UNKNOWN
所以请检查代码确保 InfoParser 请确保返回值不为 null,或提供更详细的信息
UpdateError error = getError();
if (error != null) {
onFailure(error);
} else {
UpdateInfo info = getInfo();
if (info == null) {
onFailure(new UpdateError(UpdateError.CHECK_UNKNOWN));
} else if (!info.hasUpdate) {
//...
}
}
from update.
String mCheckUrl = "http://www.baidu.com/";
UpdateManager.create(MainActivity.this).setWifiOnly(true).setUrl(mCheckUrl).setManual(true).setNotifyId(100).setParser(new UpdateAgent.InfoParser() {
@Override
public UpdateInfo parse(String source) throws Exception {
isUpdate = true;
UpdateInfo info = new UpdateInfo();
info.hasUpdate = isUpdate;
info.updateContent = updateModel.getPd().getUPDATE_DESC();
info.versionCode = updateModel.getPd().getRELEASE();
info.versionName = "V" + updateModel.getPd().getVersion();
info.url = updateModel.getPd().getUrl() + updateModel.getPd().getAPKNAME();
info.md5 = "7accadef329703a7b72613753678a9f3";
info.size = Integer.parseInt(updateModel.getPd().getRELEASE_SIZE()) * 1024 * 1024;
info.isForce = false;
info.isIgnorable = false;
info.isSilent = false;
info.isAutoInstall = false;
return info;
}
}).setOnFailure(new UpdateAgent.OnFailureListener() {
@Override
public void onFailure(UpdateError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
}
}).check();
代码是这样,info却是返回null了,在4.4不是null。
from update.
你看下logcat有没有异常信息吧
你这代码看起来应该没什么问题,parse里如果有异常的话提示的也应该是解析错误
我找台6.0的机器看看吧
from update.
提示未知错误,如果是我的问题的话请告诉我。
from update.
我也出现这个问题 [2001]查询更新失败:未知错误 6.0以上
from update.
好像跟mCheckUrl这个参数有关,好像只能写Demo中http://client.waimai.baidu.com/message/updatetag的这个参数
from update.
好像是这样,不过这个mCheckUrl并没有什么卵用,你可以请求更新接口然后自己解析成updateInfo类型的数据,非常感谢
from update.
@gsy450896356 如果不用Demo的mCheckUrl 要怎么写?我还没找到方法 能否给我看下你的代码
from update.
@zzm123456 private void update() {
Map<String, String> params = new HashMap<>();
params.put("APKNAME", "xfzdcn.apk");
params.put("SYSTEM_ID", "1");
params.put("FKEY", MD5.Encode("APKNAME" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + ",fh,"));
final int currentVersionCode = MyUtils.getAppVersionCode(this);
final Request<String> stringRequest = NoHttp.createStringRequest(NetConfig.LOCALHOST + NetConfig.UPDATE_URL, RequestMethod.GET);
stringRequest.add(params);
RxNoHttp.request(this, stringRequest, new SimpleSubscriber<Response<String>>() {
@Override
public void onNext(Response<String> stringResponse) {
Log.e("update", stringResponse.get());
final UpdateModel updateModel = new Gson().fromJson(stringResponse.get(), UpdateModel.class);
if ("01".equals(updateModel.getResult())) {
if (updateModel.getPd().getRELEASE() > currentVersionCode) {
String mCheckUrl = "http://client.waimai.baidu.com/message/updatetag";
UpdateManager.create(MainActivity.this).setWifiOnly(true).setUrl(mCheckUrl).setManual(true).setNotifyId(100).setParser(new UpdateAgent.InfoParser() {
@Override
public UpdateInfo parse(String source) throws Exception {
isUpdate = true;
UpdateInfo info = new UpdateInfo();
info.hasUpdate = isUpdate;
info.updateContent = updateModel.getPd().getUPDATE_DESC();
info.versionCode = updateModel.getPd().getRELEASE();
info.versionName = "V" + updateModel.getPd().getVersion();
info.url = updateModel.getPd().getUrl() + updateModel.getPd().getAPKNAME();
info.md5 = "7accadef329703a7b72613753678a9f3";
info.size = Integer.parseInt(updateModel.getPd().getRELEASE_SIZE()) * 1024 * 1024;
info.isForce = false;
info.isIgnorable = false;
info.isSilent = false;
info.isAutoInstall = false;
return info;
}
}).setOnFailure(new UpdateAgent.OnFailureListener() {
@Override
public void onFailure(UpdateError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
}
}).check();
}
}
}
});
}
from update.
@czy1121 如果修改Demo中的mCheckUrl的值导致6.0以上的机子报[2001]查询更新失败:未知错误 。能否修复下
from update.
建议看下源码
UpdateChecker 类会请求 mCheckUrl
在请求返回的http status code 为200时,会解请求析返回的内容为UpdateInfo
status code不为200时没有错误提示,这是我的疏忽,下个版本会修复
请检查请求的 http status code
@Override
protected Void doInBackground(Void... params) {
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) new URL(mAgent.getUrl()).openConnection();
connection.setRequestProperty("Accept", "application/json");
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
mAgent.parse(UpdateUtil.readString(connection.getInputStream()));
}
} catch (IOException e) {
e.printStackTrace();
mAgent.setError(new UpdateError(UpdateError.CHECK_NETWORK_IO));
} finally {
if (connection != null) {
connection.disconnect();
}
}
return null;
}
from update.
@zzm123456 @gsy450896356 建议检查一下请求的http status code,也许是status code 不为200导致跳过了解析
from update.
@czy1121 如果我不想setUrl 因为我们自己服务端自己会做版本对比 我只需要对话框和后续的下载安装功能,好像没有办法调用吧,好像一定要传有效的url
from update.
@zzm123456 不冲突的吧,UpdateChecker 是用的get请求,它会获取你服务器返回的结果,在UpdateAgent.InfoParser 里把它转成 UndateInfo 就好了
以后有空可能再把这些功能再分离一下吧
from update.
Related Issues (20)
- 8.0没法用了 HOT 1
- mContext.getExternalFilesDir("").getParentFile()报NullPointerException HOT 1
- 关于URL为NULL的bug
- NotificationCompat 已经从 v7 移动到 v4 了,使用这个项目可能导致 Class Not Found 异常
- 按钮颜色怎么改 HOT 1
- 查询服务端更新版本号的json格式是怎样的 HOT 1
- 怎么支持https的下载链接?
- 请教一下大神MD5如何获取?
- 请教一下大神 渠道sChannel是什么?
- 3010~~MD5值没有问题,就是一直报3010!
- hasUpdate 判断 不科学
- 断网后怎么继续下载呢
- 有适配8.0的手机吗 HOT 4
- maxSdkVersion
- 如何显示访问网络加载进度条
- 历史安装包无法删除
- 安装APK报错 HOT 1
- 作者现在停止更新迭代了吗?
- Update over the air
- 新包哈希值 问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from update.