问题描述
在 Playstore 中为现有应用开发更新时,我在启动屏幕中包含了用于检查应用更新的代码,以便在可用时强制更新。
但应用程序一直显示“请更新”消息(R.string.msg_app_out_date),即使它是最新版本。请在下面找到启动画面活动代码。
public class ActivitySplash extends AppCompatActivity {
private Call<Setting> callbackSetting = null;
private API api;
private ProgressBar progress_bar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
api = RestAdapter.createAPI();
progress_bar = findViewById(R.id.progress_bar);
startProgressBar();
Tools.setSystemBarColor(this,android.R.color.white);
Tools.setSystemBarLight(this);
Tools.RTLMode(getwindow());
}
private void startProgressBar() {
int progress = progress_bar.getProgress();
progress = progress + 2;
if (progress > progress_bar.getMax()) progress = 0;
progress_bar.setProgress(progress);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startProgressBar();
}
},50);
}
@Override
protected void onResume() {
super.onResume();
startProcess();
}
private void startProcess() {
if (!NetworkCheck.isConnect(this)) {
showDialogFailed(getString(R.string.no_internet_text));
} else {
requestSetting();
}
}
private void requestSetting() {
if (callbackSetting != null && callbackSetting.isExecuted()) callbackSetting.cancel();
callbackSetting = api.version(Tools.getVersionCode(this));
callbackSetting.enqueue(new Callback<Setting>() {
@Override
public void onResponse(Call<Setting> call,Response<Setting> response) {
Setting resp = response.body();
if (resp != null) {
if (resp.code.equals("active")) {
ThisApp.get().setSetting(resp);
startActivityMain();
} else if (resp.code.equals("inactive")) {
showDialogoutOfDate();
} else if (resp.code.equals("invalid_security")) {
showDialogFailed(getString(R.string.Failed_security_text));
} else {
onFailRequest();
}
} else {
onFailRequest();
}
}
@Override
public void onFailure(Call<Setting> call,Throwable t) {
onFailRequest();
}
});
}
private void onFailRequest() {
showDialogFailed(getString(R.string.Failed_text));
}
private void showDialogFailed(String message) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
builder.setIcon(Tools.tintDrawable(this,R.drawable.ic_report_outline,R.color.colorError));
builder.setTitle(R.string.Failed);
builder.setMessage(Tools.fromHtml(message));
builder.setCancelable(true);
builder.setPositiveButton(R.string.RETRY,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
retryOpenApplication();
}
});
builder.show();
}
private void showDialogoutOfDate() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
builder.setIcon(Tools.tintDrawable(this,R.drawable.ic_info,R.color.colorError));
builder.setTitle(R.string.info);
builder.setMessage(R.string.msg_app_out_date);
builder.setCancelable(false);
builder.setPositiveButton(R.string.UPDATE,int which) {
dialog.dismiss();
Tools.rateAction(ActivitySplash.this);
}
});
builder.show();
}
// make a delay to start next activity
private void retryOpenApplication() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startProcess();
}
},2000);
}
private void startActivityMain() {
Intent i = new Intent(ActivitySplash.this,ActivityMain.class);
startActivity(i);
finish();
}
@Override
public void onDestroy() {
if (callbackSetting != null && !callbackSetting.isCanceled()) callbackSetting.cancel();
super.onDestroy();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)