How to use an In app update API | Support in app update api
How to use an In-app update API
In this post, we use In-App Update API of the Android app. By using this API, when an update is available then it will show you a notification about update your app and by clicking on update, it installs an update inside your app without interacting with the play store.
To use In-app update API, in the android app we use a Play core library in our Gradle file.
Use In-app Update API code anywhere in your MainActivity or after your Sign-in Activity where you want to tell users about the new updates.
build.gradle
implementation 'com.google.android.play:core:1.7.3'
Then in your Java file add this code
import androidx.appcompat.app.AppCompatActivity;
import android.content.IntentSender;
import android.os.Bundle;
import com.google.android.play.core.appupdate.AppUpdateInfo;
import com.google.android.play.core.appupdate.AppUpdateManager;
import com.google.android.play.core.appupdate.AppUpdateManagerFactory;
import com.google.android.play.core.install.model.AppUpdateType;
import com.google.android.play.core.install.model.UpdateAvailability;
import com.google.android.play.core.tasks.OnSuccessListener;
public class Sample extends AppCompatActivity {
AppUpdateManager appUpdateManager;
int RequestUpdate = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
//use this anywhere in your start screen activity, like after sign in activity
appUpdateManager = AppUpdateManagerFactory.create(this);
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo result) {
if((result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
&& result.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE))
{
try {
appUpdateManager.startUpdateFlowForResult(
result,
AppUpdateType.IMMEDIATE,
Sample.this,
RequestUpdate);
}
catch (IntentSender.SendIntentException e)
{
e.printStackTrace();
}
}
}
});
}
@Override
protected void onResume() {
super.onResume();
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo result) {
if(result.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS)
{
try {
appUpdateManager.startUpdateFlowForResult(
result,
AppUpdateType.IMMEDIATE,
Sample.this,
RequestUpdate);
}
catch (IntentSender.SendIntentException e)
{
e.printStackTrace();
}
}
}
});
}
}
// After this code, you have successfully implement update API
// To Test this code goto play console, Open your App
// Under Development tools, under Internal app sharing upload your apk and then again generate signed bundle with higher
// version name and check your app update status from installed apk.
// Thanks//
If you want to test an app update then here is the solution for that.
Open your app on Google Play Console. Then Under Development Tools -> Open Internal App Sharing
Then Under Manage Uploaders -> Create new List -> Enter List name and Email id (only with this Email id you can update your app)
Then Update your app here or link given in manage uploaders
- In this link upload your signed APK.
- Copy link after uploading an app
- Transfer that link to your android mobile.
- Open it by logging into Email id you filled in test list
- Install an App from here.
- Then again generate a signed APK with higher version code
- Upload it to internal app sharing again.
- Again Copy new Link from there
- Transfer that link to your android mobile.
- Do not update that app from here.
- Open the app and your Update Window shown.
- Update your app within the app itself.
Subscribe to Harpreet studio on Youtube
Like Harpreet Studio on Facebook
Follow me on Instagram
very helpfull..........thanky you sir
ReplyDeleteVery helpful. Thanks
ReplyDelete