|
@@ -33,6 +33,8 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
|
|
+import com.tencent.bugly.beta.Beta;
|
|
|
|
|
+import com.tencent.bugly.beta.UpgradeInfo;
|
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
import com.zhy.http.okhttp.callback.FileCallBack;
|
|
import com.zhy.http.okhttp.callback.FileCallBack;
|
|
|
|
|
|
|
@@ -61,6 +63,8 @@ import rx.schedulers.Schedulers;
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
*/
|
|
*/
|
|
|
public class SysAppUtil {
|
|
public class SysAppUtil {
|
|
|
|
|
+
|
|
|
|
|
+ private static DialogConfig dialogConfig;
|
|
|
public static void startAlermApp(Activity activity, String msg, int hour, int min){
|
|
public static void startAlermApp(Activity activity, String msg, int hour, int min){
|
|
|
boolean notDone = true;
|
|
boolean notDone = true;
|
|
|
if(Build.VERSION.SDK_INT > 18) {
|
|
if(Build.VERSION.SDK_INT > 18) {
|
|
@@ -373,6 +377,14 @@ public class SysAppUtil {
|
|
|
* @param action1 动作完成后的回调
|
|
* @param action1 动作完成后的回调
|
|
|
*/
|
|
*/
|
|
|
public static void showVersionInfo(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
|
|
public static void showVersionInfo(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
|
|
|
|
|
+ if(checkBuglyUpdate()){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(dialogConfig == null)
|
|
|
|
|
+ dialogConfig = new DialogConfig();
|
|
|
|
|
+ if(dialogConfig.isShow()){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(SheepApp.getInstance().getConnectAddress().getVersionType())
|
|
SheepApp.getInstance().getNetComponent().getApiService().getNewVersion(SheepApp.getInstance().getConnectAddress().getVersionType())
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
@@ -395,14 +407,15 @@ public class SysAppUtil {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
String fileMD5 = SysAppUtil.getConnectAdrressFileMD5();
|
|
String fileMD5 = SysAppUtil.getConnectAdrressFileMD5();
|
|
|
- if(fileMD5 == null){
|
|
|
|
|
|
|
+ int versionCode = SysAppUtil.getAppVersionCode();
|
|
|
|
|
+ if(versionCode == 0){
|
|
|
if(ignoreMd5 == null)
|
|
if(ignoreMd5 == null)
|
|
|
G.showToast(baseMessage);
|
|
G.showToast(baseMessage);
|
|
|
if(action1 != null)
|
|
if(action1 != null)
|
|
|
action1.call(0);
|
|
action1.call(0);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if(fileMD5.equalsIgnoreCase(version.getMd5_address())){//已经是最新版本
|
|
|
|
|
|
|
+ if(versionCode >= version.getVersion_number()){//已经是最新版本
|
|
|
if(ignoreMd5 == null)
|
|
if(ignoreMd5 == null)
|
|
|
G.showToast("当前版本为最新版本,无需更新");
|
|
G.showToast("当前版本为最新版本,无需更新");
|
|
|
if(action1 != null)
|
|
if(action1 != null)
|
|
@@ -410,7 +423,7 @@ public class SysAppUtil {
|
|
|
} else {//有新版本
|
|
} else {//有新版本
|
|
|
final String fileName = version.getMd5_address()+".apk";
|
|
final String fileName = version.getMd5_address()+".apk";
|
|
|
final File file = new File(ClassFileHelper.DIR, fileName);
|
|
final File file = new File(ClassFileHelper.DIR, fileName);
|
|
|
- DialogConfig dialogConfig = new DialogConfig().setTitle("小绵羊V"+version.getVersion_name());
|
|
|
|
|
|
|
+ dialogConfig.setTitle("小绵羊V"+version.getVersion_name());
|
|
|
dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setLayoutId(R.layout.x_msg_wv_dialog)
|
|
dialogConfig.setMsg(TextUtils.isEmpty(version.getUpdate_content()) ? "当前版本小绵羊V"+getConnectAdrressPackageInfo().versionName : version.getUpdate_content()).setLayoutId(R.layout.x_msg_wv_dialog)
|
|
|
.setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
.setBtnLeftText(file.exists() ? "立即安装" : "立即更新").setBtnLeftNotDissDialog(true).setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
|
private void installApk(File file){
|
|
private void installApk(File file){
|
|
@@ -420,6 +433,7 @@ public class SysAppUtil {
|
|
|
}
|
|
}
|
|
|
@Override
|
|
@Override
|
|
|
public void onClick(final View view) {
|
|
public void onClick(final View view) {
|
|
|
|
|
+
|
|
|
if(file.exists()){//直接安装
|
|
if(file.exists()){//直接安装
|
|
|
installApk(file);
|
|
installApk(file);
|
|
|
} else if(TextUtils.isEmpty(version.getAddress())){//地址错误
|
|
} else if(TextUtils.isEmpty(version.getAddress())){//地址错误
|
|
@@ -493,4 +507,25 @@ public class SysAppUtil {
|
|
|
LogUtil.println("FileMD5", fileMD5);
|
|
LogUtil.println("FileMD5", fileMD5);
|
|
|
return fileMD5;
|
|
return fileMD5;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static int getAppVersionCode() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ PackageInfo info = getConnectAdrressPackageInfo();
|
|
|
|
|
+ return info.versionCode;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * bugly 检查更新
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean checkBuglyUpdate(){
|
|
|
|
|
+ Beta.checkUpgrade();
|
|
|
|
|
+ UpgradeInfo upgradeInfo = Beta.getUpgradeInfo();
|
|
|
|
|
+ if(upgradeInfo != null)
|
|
|
|
|
+ return true;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|