I am following below link to provide app update experience or feature in my android live application.
The link is here : https://developer.android.com/guide/playcore/in-app-updates#java
From the link content, I am implementing Immediate App Update feature.
So far, I have done as below steps :
Implemented below Code :
First added dependency : implementation 'com.google.android.play:core:1.7.1'
Then, In Splash Activity,
// Creates instance of the manager.
final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(SplashActivity.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(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)) {
// Request the update.
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, SplashActivity.this,500);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}else
{
//Continuing with the Application flow
}
}
The Issue is: When I have generated Signed APK and installed in My android device.
Getting below error in log :
Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:9494777414>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/emeraldsea.mobileapps.doritos.cookie
What might be the Issue ?
Got the Solution :
While testing the App update functionality :
Your installed app version and version code must be lesser than that of the one which is live on Play Store.
Test it in Real Android Device instead of AVD or Emulator.
The Code in asked question is correct, But must handle the callback in onActivityResult method.
From Google,
With internal app sharing, you can quickly share an app bundle or APK with your internal team and testers by uploading the app bundle you want to test to the Play Console.
You can also use internal app sharing to test in-app updates, as follows:
On your test device, make sure you've already installed a version of your app that meets the following requirements:
The app was installed using an internal app sharing URL Supports in-app updates Uses a version code that's lower than the updated version of your app Follow the Play Console instructions on how to share your app internally. Make sure you upload a version of your app that uses a version code that's higher than the one you have already installed on the test device. On the test device, only click the internal app-sharing link for the updated version of your app. Do not install the app from the Google Play Store page you see after clicking the link.
Open the app from the device's app drawer or home screen. The update should now be available to your app, and you can test your implementation of in-app updates.
That's ALL.