我发现了 2 个链接,我认为它会是正确的,但是在构建该代码之后它什么也没显示。我正在添加两个之一,最近构建了一个应用程序。
链接已接受答案,但它没有在我的应用程序中运行,我无法找到我错过的内容
注意: -代码和链接有不同的代码。
代码
public class TestingActivity extends AppCompatActivity {
private static final String TAG = "ResTest";
private CoordinatorLayout coordinatorLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing);
// coordinatorLayout = findViewById(R.id.res_test);
// Initialize AppUpdateManager. AppUpdateManager helps to Manages operations that allow your app to initiate its own updates.
final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(TestingActivity.this);
// Requests the update availability for the current app, an intent to start an update flow, and, if applicable, the state of updates currently in progress.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
// InstallStateUpdatedListener is listener that used to monitor updates installs.
final InstallStateUpdatedListener installStateUpdatedListener = new InstallStateUpdatedListener() {
@Override
public void onStateUpdate(InstallState installState) {
// If successfully download then call popupSnackBarForCompleteUpdate() to show snackbar of successfully downloaded latest update.
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
// popupSnackBarForCompleteUpdate(coordinatorLayout, appUpdateManager);
Toast.makeText(TestingActivity.this, String.valueOf( appUpdateManager.completeUpdate()), Toast.LENGTH_SHORT).show();
}
}
};
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo appUpdateInfo) {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
// As it's flexible update so use FLEXIBLE.
appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
// Log.d(TAG, "app here 1");
// Request the update.
try {
appUpdateManager.registerListener(installStateUpdatedListener);
// Starts the desired update flow(HERE is FLEXIBLE update).
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, TestingActivity.this, 100);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
} else {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
popupSnackBarForCompleteUpdate(coordinatorLayout, appUpdateManager);
}
}
}
});
}
private static void popupSnackBarForCompleteUpdate(View view, final AppUpdateManager appUpdateManager) {
Snackbar snackbar = Snackbar.make(view, "An update has just been downloaded.", Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("RESTART", new View.OnClickListener() {
@Override
public void onClick(View view) {
appUpdateManager.completeUpdate();
}
});
snackbar.show();
}
}
当我在调试中构建此代码时,我什么也没发现。当应用程序已在 Play 商店中发布时,此处不显示更新弹出窗口。
我想要的是
帮助在应用中使用应用内更新 API,如果您知道,请解释应用内更新 API 的流程。