Last active
January 22, 2023 04:43
-
-
Save walteranyika/df8fc2e4e0f3561c6f931e95409d482d to your computer and use it in GitHub Desktop.
The check for updates function used to do in app updates from google play store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add this to gradle | |
// implementation 'com.google.android.play:core:1.5.0' | |
private static final int MY_REQUEST_CODE = 2399; | |
private void checkForUpdates() { | |
final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this); | |
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo(); | |
// 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 | |
// For a flexible update, use AppUpdateType.FLEXIBLE | |
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) { | |
try { | |
appUpdateManager.startUpdateFlowForResult( | |
// Pass the intent that is returned by 'getAppUpdateInfo()'. | |
appUpdateInfo, | |
// Or 'AppUpdateType.FLEXIBLE' for flexible updates. | |
AppUpdateType.IMMEDIATE, | |
// The current activity making the update request. | |
MainActivity.this, | |
// Include a request code to later monitor this update request. | |
MY_REQUEST_CODE); | |
} catch (IntentSender.SendIntentException e) { | |
e.printStackTrace(); | |
} | |
}else if(appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE | |
// For a flexible update, use AppUpdateType.FLEXIBLE | |
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)){ | |
try { | |
appUpdateManager.startUpdateFlowForResult( | |
// Pass the intent that is returned by 'getAppUpdateInfo()'. | |
appUpdateInfo, | |
// Or 'AppUpdateType.FLEXIBLE' for flexible updates. | |
AppUpdateType.FLEXIBLE, | |
// The current activity making the update request. | |
MainActivity.this, | |
// Include a request code to later monitor this update request. | |
MY_REQUEST_CODE); | |
} catch (IntentSender.SendIntentException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
}); | |
} | |
//UPDATE_STATUS | |
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == MY_REQUEST_CODE) { | |
if (resultCode != RESULT_OK) { | |
Log.e("UPDATE_STATUS","Update flow failed! Result code: " + resultCode); | |
// If the update is cancelled or fails, | |
// you can request to start the update again. | |
} | |
} | |
} |
I will definitely write an update it to accommodate this new change
👍
@walteranyika Any update?
have you
wrote anything on this update?
Any updates ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@walteranyika
onActivityResult
is deprecated in recent androidX update becomesregisterForActivityResult
combing withstartActivityForResult
, but appUpdateManager is separate withstartUpdateFlowForResult
, what should we do?