Android 每次都会弹出InAppUpdate对话框,即使我单击update按钮
我在play store中发布了一个版本代码为3的应用程序,在新版本中,我希望实现应用程序内更新功能,因此在build.gradle中我添加:Android 每次都会弹出InAppUpdate对话框,即使我单击update按钮,android,in-app-update,google-play-core,Android,In App Update,Google Play Core,我在play store中发布了一个版本代码为3的应用程序,在新版本中,我希望实现应用程序内更新功能,因此在build.gradle中我添加: implementation 'com.google.android.play:core:1.8.2' 在主要活动中: public class MainActivity extends BaseActivity { //... private AppUpdateManager mAppUpdateManager; @Over
implementation 'com.google.android.play:core:1.8.2'
在主要活动中:
public class MainActivity extends BaseActivity {
//...
private AppUpdateManager mAppUpdateManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//....
checkForUpdate();
}
/**
* check for update
*/
private void checkForUpdate() {
// Creates instance of the manager.
mAppUpdateManager = AppUpdateManagerFactory.create(this);
mAppUpdateManager.registerListener(state -> {
if (state.installStatus() == InstallStatus.DOWNLOADED) {
// After the update is downloaded, show a notification
// and request user confirmation to restart the app.
popupSnackbarForCompleteUpdate();
}
});
// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = mAppUpdateManager.getAppUpdateInfo();
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
//&& appUpdateInfo.clientVersionStalenessDays() != null
//&& appUpdateInfo.clientVersionStalenessDays() >= DAYS_FOR_FLEXIBLE_UPDATE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
// Request the update.
try {
mAppUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.IMMEDIATE' for flexible updates.
AppUpdateType.FLEXIBLE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
Toast.makeText(this, R.string.update_failed, Toast.LENGTH_SHORT).show();
}
}
});
}
/**
* Displays the snackbar notification and call to action.
*/
private void popupSnackbarForCompleteUpdate() {
final Snackbar snackbar =
Snackbar.make(
findViewById(R.id.activity_main_layout),
R.string.an_update_has_been_just_downloaded,
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.install, view -> mAppUpdateManager.completeUpdate());
snackbar.setActionTextColor(
ContextCompat.getColor(this, R.color.color_snackbar_action_text_color));
snackbar.show();
}
}
public类MainActivity扩展了BaseActivity{
//...
私有AppUpdateManager mAppUpdateManager;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_活动);
//....
checkForUpdate();
}
/**
*检查更新
*/
私有void checkForUpdate(){
//创建管理器的实例。
mAppUpdateManager=AppUpdateManager.create(此);
mAppUpdateManager.registerListener(状态->{
if(state.installStatus()==installStatus.download){
//下载更新后,显示通知
//并请求用户确认以重新启动应用程序。
PopupNackBarforCompleteUpdate();
}
});
//返回用于检查更新的意图对象。
Task AppUpdateInfo任务=mAppUpdateManager.getAppUpdateInfo();
//检查平台是否允许指定类型的更新。
appUpdateInfo任务。addOnSuccessListener(appUpdateInfo->{
如果(appUpdateInfo.updateAvailability()==updateAvailability.UPDATE\u可用
//&&appUpdateInfo.ClientVersionStalenesDays()!=null
//&&appUpdateInfo.ClientVersionStalenesDays()>=灵活更新的天数
&&appUpdateInfo.IsUpdateType允许(AppUpdateType.FLEXIBLE)){
//请求更新。
试一试{
mAppUpdateManager.startUpdateFlowForResult(
//传递“getAppUpdateInfo()”返回的意图。
appUpdateInfo,
//或“AppUpdateType.IMMEDIATE”进行灵活更新。
AppUpdateType.FLEXIBLE,
//发出更新请求的当前活动。
这
//包括请求代码,以便以后监视此更新请求。
我的_请求_代码);
}catch(IntentSender.sendtintentexe){
Toast.makeText(this,R.string.update_失败,Toast.LENGTH_SHORT).show();
}
}
});
}
/**
*显示snackbar通知和行动调用。
*/
私有void popupnackbarforCompleteUpdate(){
最终小吃条小吃条=
Snackbar.make(
findViewById(R.id.activity\u main\u布局),
R.string.a\u更新\u刚刚下载,
蛇形杆。长度(不确定);
setAction(R.string.install,view->mAppUpdateManager.completeUpdate());
snackbar.setActionTextColor(
getColor(这个,R.color.color\u snackbar\u action\u text\u color));
snackbar.show();
}
}
为了能够测试此功能,我将版本代码更改为低于Playstore中发布的版本代码(本例中为2,应用程序发布为3)。当我运行应用程序时,它会显示更新应用程序的对话框,当我单击“更新”按钮时,更新启动并安装,没有任何错误,但当应用程序重新启动时,它再次向我显示更新对话框,应用程序似乎没有更新,我不知道这是否是我的应用程序中的错误,或者我应该将应用程序上载到play store才能正常工作
我正在使用应用程序包(.aab)在哪里检查此版本代码低于下载的版本代码???@Ali Vatanparast play core library请为我检查