Я следовал процессу, указанному в документации для разработчиков, и загрузил приложения, чтобы поделиться ими с тестерами. Но, к сожалению, это не работает. Кроме кода для обновления типа IMMEDIATE, нужно ли нам что-то еще делать в консоли разработчика Play или в удаленной конфигурации панели мониторинга, где мы должны указать тип IMMEDIATE или FLEXIBLE?
Код:
public class SplashActivity extends AppCompatActivity {
private KeyStorePref keyStorePref;
private static final String TAG = "SplashActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
}
private void forceUpdateApplication() {
// Creates instance of the manager.
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE)) {
// Request the update.
Toast.makeText(this, "forceUpdateApplication: need to update", Toast.LENGTH_LONG).show();
try {
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
IMMEDIATE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
101);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
} else {
Toast.makeText(this, "forceUpdateApplication: No need to update", Toast.LENGTH_LONG).show();
moveToDashboardActivity();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101) {
if (resultCode != RESULT_OK) {
Log.i("SplashActivity", "Update flow failed!: " + resultCode);
// If the update is cancelled or fails,
// you can request to start the update again.
forceUpdateApplication(); // Calling it again.
} else if (requestCode == RESULT_OK) {
moveToDashboardActivity();
} else if (requestCode == RESULT_CANCELED) {
finishAffinity();
}
}
}
public void moveToDashboardActivity() {
FirebaseMessaging.getInstance().subscribeToTopic("global"); // This is done to subscribe all app user for topic
keyStorePref = KeyStorePref.getInstance(this);
int SPLASH_TIME_OUT = 3000;
new Handler().postDelayed(() -> {
if (keyStorePref.getBoolean(KEY_USER_LOGIN_STATUS)) {
startActivity(new Intent(this, DashboardActivity.class));
} else {
startActivity(new Intent(this, LoginActivity.class));
}
}, SPLASH_TIME_OUT);
}
// Checks that the update is not stalled during 'onResume()'.
// However, you should execute this check at all entry points into the app.
@Override
protected void onResume() {
super.onResume();
forceUpdateApplication();
}
}