У меня есть переменная remote-config с именем "min_version" , которая указывает минимальную версию, которую я не имел для пользователей, если у них версия ниже, чем эта - обновлениепредупреждение появится.Проблема заключается в том, что при обновлении удаленной конфигурации на firebase информация недоступна приложению в onStart () и не запрашивает функцию обновления в приложении.ТОЛЬКО при переходе к настройкам приложения и нажатии «очистить данные» оно будет корректно обновлять выборку информации, но ни один пользователь не сделает этого ...
вот мой код -
@Override
protected void onStart() {
super.onStart();
// navigation drawer
checkValidFacebookSession();
initDrawerMenu();
// network monitoring
registerNetworkReceiver();
// monitoring upload
LocalBroadcastManager.getInstance(this).registerReceiver(mUploadReceiver, new IntentFilter(ULBroadcastConstants.UPLOAD_STATUS_ACTION));
LocalBroadcastManager.getInstance(this).registerReceiver(mFCMReceiver, new IntentFilter(MyFirebaseMessagingService.RECEIVED_FCM_ACTION));
checkInAppUpdate();
}
private void checkInAppUpdate() {
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(App.getAppContext());
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
checkUpdateInProgress(appUpdateManager, appUpdateInfo);
checkUpdateAvailable(appUpdateManager, appUpdateInfo);
});
}
private void checkUpdateInProgress(AppUpdateManager appUpdateManager, AppUpdateInfo appUpdateInfo) {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
//if an in app update is already running - resume the update
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, this, VERSION_UPDATE_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
private void checkUpdateAvailable(AppUpdateManager appUpdateManager, AppUpdateInfo appUpdateInfo) {
getMinAppVersion(() -> {
int currentVersionCode = BuildConfig.VERSION_CODE;
if (currentVersionCode < min_version && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, this, VERSION_UPDATE_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
});
}
private void getMinAppVersion(OnRemoteConfigFetchComplete listener){ // <- this is the function that gets the remote config information and fails (returns the last saved variable) without cleaning application data.
//fetching the min_version parameter from 'remote config' of Firebase and saves it to our local variable.
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(200).build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
mFirebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
min_version = mFirebaseRemoteConfig.getLong(RemoteConfigUtil.MIN_VERSION);
listener.onFetchComplete();
} else {
Timber.tag("min version").d("error while fetching and activating remove config");
}
});
}