Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2001]查询更新失败:未知错误 #11

Closed
caojunJackson opened this issue Jan 20, 2017 · 17 comments
Closed

[2001]查询更新失败:未知错误 #11

caojunJackson opened this issue Jan 20, 2017 · 17 comments

Comments

@caojunJackson
Copy link

[2001]查询更新失败:未知错误

@gsy450896356
Copy link

我也出现这个问题,6.0手机

@czy1121
Copy link
Owner

czy1121 commented Feb 20, 2017

是因为解析得到的 UpdateInfo 为 null
如果设置了UpdateAgent.InfoParser 请确保返回值不为 null

@gsy450896356
Copy link

在4.4手机上正常,6.0就是这样了

@czy1121
Copy link
Owner

czy1121 commented Feb 20, 2017

看代码,只有解析返回的 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) { 
//...
            }
        }

@gsy450896356
Copy link

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。

@czy1121
Copy link
Owner

czy1121 commented Feb 20, 2017

你看下logcat有没有异常信息吧
你这代码看起来应该没什么问题,parse里如果有异常的话提示的也应该是解析错误
我找台6.0的机器看看吧

@gsy450896356
Copy link

提示未知错误,如果是我的问题的话请告诉我。

@zzm123456
Copy link

我也出现这个问题 [2001]查询更新失败:未知错误 6.0以上

@zzm123456
Copy link

好像跟mCheckUrl这个参数有关,好像只能写Demo中http://client.waimai.baidu.com/message/updatetag的这个参数

@gsy450896356
Copy link

gsy450896356 commented Feb 21, 2017

好像是这样,不过这个mCheckUrl并没有什么卵用,你可以请求更新接口然后自己解析成updateInfo类型的数据,非常感谢

@zzm123456
Copy link

@gsy450896356 如果不用Demo的mCheckUrl 要怎么写?我还没找到方法 能否给我看下你的代码

@gsy450896356
Copy link

@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();
                }
            }
        }
    });


}

@zzm123456
Copy link

@czy1121 如果修改Demo中的mCheckUrl的值导致6.0以上的机子报[2001]查询更新失败:未知错误 。能否修复下

@czy1121
Copy link
Owner

czy1121 commented Feb 21, 2017

建议看下源码
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;
    }

@czy1121
Copy link
Owner

czy1121 commented Feb 21, 2017

@zzm123456 @gsy450896356 建议检查一下请求的http status code,也许是status code 不为200导致跳过了解析

@zzm123456
Copy link

@czy1121 如果我不想setUrl 因为我们自己服务端自己会做版本对比 我只需要对话框和后续的下载安装功能,好像没有办法调用吧,好像一定要传有效的url

@czy1121
Copy link
Owner

czy1121 commented Feb 21, 2017

@zzm123456 不冲突的吧,UpdateChecker 是用的get请求,它会获取你服务器返回的结果,在UpdateAgent.InfoParser 里把它转成 UndateInfo 就好了
以后有空可能再把这些功能再分离一下吧

@czy1121 czy1121 closed this as completed Feb 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants