Google Play InApp update feature is not working, throwing Unbind from service

  Kiến thức lập trình

I am trying to add the InApp Update feature to my new project in Android Studio. But when I ran the program it not update the latest version from the Play Store. Instead it keep running the old version. But as per the below program, it should check for whether new updates are available that app, if available it should ask the user to update or Not.

LOG:

2024-04-04 14:32:26.836 8935-8991/com.homeapps.dictionary.ingredients I/Gralloc4: mapper 4.x is    not supported
2024-04-04 14:32:28.874 8935-8935/com.homeapps.dictionary.ingredients W/ary.ingredient:    Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2024-04-04 14:32:29.176 8935-8935/com.homeapps.dictionary.ingredients I/PlayCore: UID: [10159]  PID: [8935] AppUpdateService : requestUpdateInfo(com.homeapps.dictionary.ingredients)
2024-04-04 14:32:29.190 8935-9026/com.homeapps.dictionary.ingredients I/PlayCore: UID: [10159]  PID: [8935] AppUpdateService : Initiate binding to the service.
2024-04-04 14:32:34.699 8935-8935/com.homeapps.dictionary.ingredients I/PlayCore: UID: [10159]  PID: [8935] AppUpdateService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.installservice.DevTriggeredUpdateService})
2024-04-04 14:32:34.703 8935-9026/com.homeapps.dictionary.ingredients I/PlayCore: UID: [10159]  PID: [8935] AppUpdateService : linkToDeath
2024-04-04 14:32:41.252 8935-9026/com.homeapps.dictionary.ingredients I/PlayCore: UID: [10159]  PID: [8935] AppUpdateService : Unbind from service.

And My Java Coding here

// App Update Functionality

private void CheckForAppUpdate() {
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
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {

// Create an activity result launcher for the update flow

// Start the update flow using the activity result launcher
try {
appUpdateManager.startUpdateFlowForResult(

appUpdateInfo,
AppUpdateType.FLEXIBLE,
// Pass the activity result launcher
MainActivity.this,
REQUEST_CODE
);
} catch (IntentSender.SendIntentException e) {
throw new RuntimeException(e);
}
}
});

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MY_REQUEST_CODE) {
if (resultCode != RESULT_OK) {
Log.w("FirstActivity", "Update flow failed! Result code:" + resultCode);
}
}
}

@Override
protected void onStop() {
super.onStop();
appUpdateManager.unregisterListener(listener);
}

InstallStateUpdatedListener listener = state -> {
if (state.installStatus() == InstallStatus.DOWNLOADED) {
popupSnackbarForCompleteUpdate();
}

};

// Displays the snackbar notification and call to action.
private void popupSnackbarForCompleteUpdate() {
Snackbar snackbar =
Snackbar.make(
findViewById(android.R.id.content),
"An update has just been downloaded.",
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("RESTART", view -> appUpdateManager.completeUpdate());
snackbar.setActionTextColor(
getResources().getColor(android.R.color.holo_blue_bright));
snackbar.show();
}`

I am using FLEXIBLE Update here, which means user can update it through background while using the app or may update it later. This app doesn’t have any signin or login options

LEAVE A COMMENT