Giter Site home page Giter Site logo

Comments (17)

gsy450896356 avatar gsy450896356 commented on August 27, 2024

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

from update.

czy1121 avatar czy1121 commented on August 27, 2024

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

from update.

gsy450896356 avatar gsy450896356 commented on August 27, 2024

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

from update.

czy1121 avatar czy1121 commented on August 27, 2024

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

gsy450896356 avatar gsy450896356 commented on August 27, 2024
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.

czy1121 avatar czy1121 commented on August 27, 2024

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

from update.

gsy450896356 avatar gsy450896356 commented on August 27, 2024

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

from update.

zzm123456 avatar zzm123456 commented on August 27, 2024

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

from update.

zzm123456 avatar zzm123456 commented on August 27, 2024

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

from update.

gsy450896356 avatar gsy450896356 commented on August 27, 2024

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

from update.

zzm123456 avatar zzm123456 commented on August 27, 2024

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

from update.

gsy450896356 avatar gsy450896356 commented on August 27, 2024

@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.

zzm123456 avatar zzm123456 commented on August 27, 2024

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

from update.

czy1121 avatar czy1121 commented on August 27, 2024

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

czy1121 avatar czy1121 commented on August 27, 2024

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

from update.

zzm123456 avatar zzm123456 commented on August 27, 2024

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

from update.

czy1121 avatar czy1121 commented on August 27, 2024

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

from update.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.