Using InApp Update API mode Flexible - android

I was using In App Update API with update type as Flexible using below code
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE,
this,
APP_UPDATE_REQUEST_CODE)
Where the update type is provided as AppUpdateType.FLEXIBLE.
It showcases the correct UI where it provides option for users to either select Update or No Thanks.
As showcased in below image.
However clicking on Update actually showcases a fullscreen UI with progressbar generally associated with Immediate updated instead of performing the update in background.
Using play code SDK version 1.8.X
// Rate this app
// So, make sure you also include that repository in your project's build.gradle file.
implementation 'com.google.android.play:core:1.8.0'
// For Kotlin users also import the Kotlin extensions library for Play Core:
implementation 'com.google.android.play:core-ktx:1.8.1'
Does anyone has a idea why this would be happening?
Thanks in Advance.

Maybe your problem is
override fun onResume() {
super.onResume()
appUpdateManager
.appUpdateInfo
.addOnSuccessListener {
// If an in-app update is already running, resume the update.
if (it.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS)
startUpdate(it, AppUpdateType.IMMEDIATE) // <<-- !!HERE!!
// If the update is downloaded but not installed, notify the user to complete the update.
if (it.installStatus == InstallStatus.DOWNLOADED) {
nav_progress_download.hide()
popupSnackbarForCompleteUpdate()
}
}
}
When you click Update button, onResume is called.
And updateAvailability() of AppUpdateType.FLEXIBLE is same as UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
Check this...
How to know the AppUpdateType at the origin of the DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS update availability?
https://issuetracker.google.com/issues/153785560

Related

Popup for Google Play Store Update is not showing on Tablet?

I have a strange behavior in my Android application. I want to create a popup if a new update is available on Google Play Store. On my Smartphone it is shown without any problems. But on my Samsung Tablet (Galaxy Tab S7), the popup does not show up. I cannot figure out why this happens. I tried it also some hours later.
I tried to clear the cache of the play store. WiFi is enabled and the Android version is Android 11.
My code:
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
// This example applies an immediate update. To apply a flexible update
// instead, pass in 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.
this,UPDATE_APP
// Include a request code to later monitor this update request.
);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
});
Do you have any idea why the popup for an update is not showing up? In the google play store, there is an update button if I open the app.

Android Studio Constantly Shows Error While Creating An Instance of ActivityResultCallback

I started learning about how I can request app permissions from the Google Documentation. This is basically the code that I'm trying to execute.
// Register the permissions callback, which handles the user's response to the
// system permissions dialog. Save the return value, an instance of
// ActivityResultLauncher. You can use either a val, as shown in this snippet,
// or a lateinit var in your onAttach() or onCreate() method.
val requestPermissionLauncher =
registerForActivityResult(RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
// Permission is granted. Continue the action or workflow in your
// app.
} else {
// Explain to the user that the feature is unavailable because the
// features requires a permission that the user has denied. At the
// same time, respect the user's decision. Don't link to system
// settings in an effort to convince the user to change their
// decision.
}
}
Unfortunately, whenever I'm trying to write the registerForActivityResult(...) part, Android Studio keeps highlighting it as an error.
There's another step that I need to perform along with this. It tells me to add this dependency. Even after doing that, Android Studio still shows me that it shows an error. Can anyone tell me why this happens?
You're missing the following
// Kotlin
implementation 'androidx.activity:activity-ktx:1.2.0-beta01'
implementation 'androidx.fragment:fragment-ktx:1.3.0-beta01'

How to open in app dialog when update is available

I have refer this link to implement but dialog not showing.
override fun onResume() {
super.onResume()
val appUpdateManager = AppUpdateManagerFactory.create(this)
appUpdateManager.appUpdateInfo
.addOnSuccessListener {
if (it.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
// resume the update flow
appUpdateManager.startUpdateFlowForResult(
it,
IMMEDIATE,
this,
123)
}
}
}
decrease my current version and check but "addOnSuccessListener" listener not calling.
I have the same confusion when I implemented this. But It takes time.
It will not work immediately. You will get it in 24 hours as per my experience.
For more information, you can have a look at this S.O. answer. I followed the same and It's working now.
It worked for some device on the same day and for other devices, in-app dialog came the next day. We've tested with various devices without any issue. you just need to wait for a while.

Flexible In-App update installed while app is in background

I'm using Android Play Core Library's new feature In-App Updates.
So the documentation says that for a Flexible In-App Update, I need an InstallStateUpdatedListener which would listen for when the update is downloaded in the background, and then we need to show a UI or in my case a Snackbar to the user, describing that the user now needs to install the already downloaded update. This works fine when I'm in the foreground for the whole time, but when I go to the background before the in-app update is downloaded and then return to the foreground of the app after some time, my app automatically gets updated without showing any UI to the user asking them to install the update. This should not happen ideally as per the docs.
I've tried removing all kind of listeners, commenting out the code which completes the update, but to no avail.
appUpdateManager = AppUpdateManagerFactory.create(getAppContext());
if (appUpdateInfo.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
final InstallStateUpdatedListener listener =
new InstallStateUpdatedListener() {
#Override
public void onStateUpdate(InstallState installState) {
if (installState.installStatus() ==
InstallStatus.DOWNLOADED) {
showUpdateCompletedSnackbar();
}
}
};
appUpdateManager.registerListener(listener);
try {
Log.d("BaseApp","Starting Flexible in app update");
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE,
getActivity(),
2000);
} catch (IntentSender.SendIntentException exception) {
Log.e("BaseApp",exception);
}
}
private static void showUpdateCompletedSnackbar() {
Snackbar snackbar =
Snackbar.make(getContainer(),
appContext.getString(R.string.in_app_update_snackbar_text),
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("INSTALL", new View.OnClickListener() {
#Override
public void onClick(View v) {
appUpdateManager.completeUpdate();
}
});
snackbar.setActionTextColor(
ContextCompat.getColor(getAppContext(), R.color.blue));
snackbar.show();
}
Okay, so actually the documentation was not that clear about this, but one caveat in the Flexible In-app update is that, once you start downloading the in-app update and you continue using the app, the update will download in the background and then will notify the user through a UI that the Update has been downloaded and we need to install the update (this showing of UI and all will be handled by the developer).
But the second case, of which I had an issue, was that what if, before the update is downloaded, I move my app to the background. In that case, if the update is downloaded while the app is in the background, then it will install the update too without informing the user to the new version and then when you take your app to the foreground, you'll see the updated app, instead of any UI.
The Flexible update was for this only, that if the user is using the app, the update will be downloaded in the background without the user having the trouble to close the app and updating it leaving the work which they were doing in the app, and then post the update is downloaded the user will have a choice to finally install the update using a UI shown to them whenever they want or when they complete their ongoing work in the app.
There are more caveats in the app and this medium article would be helpful for you all to see more of the edge cases https://proandroiddev.com/android-in-app-updates-common-pitfalls-and-some-good-patterns-9024988bbbe8

In-app updates check whether it is AppUpdateType.FLEXIBLE or AppUpdateType.IMMEDIATE

Is there any option available in the playstore console to configure this value?
Here is the official doc. code:
// Creates instance of the manager.
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(context);
// 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(AppUpdateType.IMMEDIATE)) {
// Request the update.
}
});
How do we know about:
appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
Where to configure the above type? There is no relevant description available on the official doc.
In the AppUpdateInfo.class:
public final boolean isUpdateTypeAllowed(int var1) {
if (var1 == 0) {
return this.f != null;
} else if (var1 == 1) {
return this.e != null;
} else {
return false;
}
}
Where f and e are the PendingIntent and method returns true or false based on their value.
What is the use of appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)?
This is a very common question.
Many (myself included) interpreted this as a value that could be set somewhere dynamically, e.g. in the Google Play Console.
However that appears to not be the case. This is a local check that determines whether conditions on the device have been met to show the dialog.
If you want to dynamically configure whether to show Immediate or Flexible updates, you will need to provide it yourself, e.g. from your backend.
For more info: https://medium.com/#jplipata/undocumented-android-in-app-updates-a95efb9b7bd8?source=friends_link&sk=e8085150daa555ea80d07e8419b5341e
The update type (IMMEDIATE or FLEXIBLE) are set inside the app, not the play console.
Only an app update availibility check is necessary in the first place:
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
If this check succeeds, you need to start the update flow by yourself
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE,
or
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE,
regarding this type, the update will be installed in the background or in a blocking view by an play store overlay.
When an flexible app update is triggered and the user leaves the app, you need to check on the next launch if an flexible update is running in the background or finished.
https://developer.android.com/guide/app-bundle/in-app-updates
appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)
I have tried for multiple times to lower down the versionCode as compared to the Live App on Play Store.
Maybe in the next update, Google will explain about the isUpdateTypeAllowed because right now it's an only ambiguous call.
It is up to the developer to choose which type of update is invoked.
The mode is determined by the app in code.
Please see for further reference https://developer.android.com/guide/app-bundle/in-app-updates#start_update

Categories

Resources