CustomUpdateConfigProvider.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.emato.ich.update;
  2. import android.content.Context;
  3. import com.emato.ich.utils.Log;
  4. import androidx.annotation.NonNull;
  5. import com.xuexiang.xupdate.aria.AriaDownloadServiceProxyImpl;
  6. import com.xuexiang.xupdate.easy.config.IUpdateConfigProvider;
  7. import com.xuexiang.xupdate.easy.config.UpdateConfig;
  8. import com.xuexiang.xupdate.utils.UpdateUtils;
  9. import org.jetbrains.annotations.NotNull;
  10. /**
  11. * 自定义的XUpdate配置提供者
  12. */
  13. public class CustomUpdateConfigProvider implements IUpdateConfigProvider {
  14. private static final String TAG = CustomUpdateConfigProvider.class.getName();
  15. @NonNull
  16. @NotNull
  17. @Override
  18. public UpdateConfig getUpdateConfig(@NonNull @NotNull Context context) {
  19. return UpdateConfig.create()
  20. .setIsDebug(true) // 开启debug日志
  21. .setIsWifiOnly(false) // 设置非wifi更新
  22. .setIsGet(false) // 设置post方式获取下载参数
  23. .setIsAutoMode(true) // 设置自动更新
  24. .setParam("versionCode", UpdateUtils.getVersionCode(context)) // 设置默认公共请求参数
  25. .setParam("appKey", context.getPackageName())
  26. .setOnInstallListener(new PackageManagerCompat()) // 自定义的下载器
  27. .setOnUpdateFailureListener(error -> {
  28. Log.i(TAG, "onCreate: =====================>自动更新失败! " + error.getCode() + ", " + error.getDetailMsg());
  29. })
  30. .setIsSupportSilentInstall(true); // 设置是否支持静默安装,默认是true
  31. }
  32. }