xuexiangjys / XUpdate

🚀A lightweight, high availability Android version update framework.(一个轻量级、高可用性的Android版本更新框架)
https://github.com/xuexiangjys/XUpdate/wiki
Apache License 2.0
2.32k stars 406 forks source link

使用系统默认样式无法打开升级提示窗CustomUpdatePrompter #149

Closed aije closed 2 years ago

aije commented 2 years ago

使用自定义弹窗提示。 XUpdate.newBuild(BaseApplication.getApplication()) .updateUrl("http://192.168.1.151/update.json") .updatePrompter(new CustomUpdatePrompter()) .update();

报错提示: W/System.err: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

xuexiangjys commented 2 years ago

这是你自己代码写的有问题,知道嘛。 handler创建请指明Looper, 不要在子线程里面创建handler

aije commented 2 years ago

新建的项目,没有包含其他代码,只添加了XUpdate 报如下错误。不知道哪里写的有问题。 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

MainActivity只有以下代码:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    XUpdate.newBuild(this)
            .updateUrl("http://192.168.1.151/update.json")
            .updatePrompter(new CustomUpdatePrompter())
            .update();
}

}

在BaseApplication中初始化代码:

private void initUpdae(){ XUpdate.get() .debug(true) //设置默认只有在Wifi下检测版本 .isWifiOnly(false) //默认使用get检查版本 .isGet(true) //默认设置非自动模式,可以根据情况使用配置 .isAutoMode(false) //设置默认公共请求参数 .param("versionCode" , UpdateUtils.getVersionCode(this)) .param("appKey" , getPackageName()) //设置版本更新出错监听 .setOnUpdateFailureListener(new OnUpdateFailureListener() { @Override public void onFailure(UpdateError error) { System.out.println(error.toString()); error.printStackTrace(); if (error.getCode() != CHECK_NO_NEW_VERSION){ System.out.println(error.toString()); } } }) //设置是否支持静默安装,默认是true .supportSilentInstall(false) .setIUpdateHttpService(new OKHttpUpdateHttpService()) .init(this); }

使用demo中自带的两个类文件

image

打开APP出现如下错误。

image

aije commented 2 years ago

这是你自己代码写的有问题,知道嘛。 handler创建请指明Looper, 不要在子线程里面创建handler

.updatePrompter(new CustomUpdatePrompter())

注释上面的代码就没有问题。