I have two very similar news apps on the Play Store, let's call them app A and app B (B is similar to A, but has advanced features). Now I want all my users of app A to seamlessly migrate to app B. For that, I wish to push an app update to A, with a button titled "Upgrade to B now". When the button is tapped, I want to do two things. One is to check if B is not installed, and if it isn't I want to start downloading the app B, then proceeding to install it. Once the app is installed or if it were already installed, I wish to pass on login information to the app B and open its home page(probably using intents). The second is to delete app A once migrated to B. How can this be accomplished as seamlessly as possible so as to give the users of app A, an opportunity to start using the much better app B, with the transition happening automagically behind the scenes? I went through a few posts with people downloading custom apks, and then installing it programmatically. So probably what I could do is download the apk of B from my server, and then install it after INSTALL_PACKAGES permission is granted by the user. Is this the right way to go about this?
Asked
Active
Viewed 92 times
1 Answers
0
once the user clicks the install button. check whether the app B installed otherwise you can direct him to the playstore of app B, use the below code to achieve this.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add respective layout
setContentView(R.layout.main_activity);
// Use package name which we want to check
boolean isAppInstalled = appInstalledOrNot("Package name of your App B");
if(isAppInstalled) {
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("Package name of your App B");
startActivity(LaunchIntent);
Log.i("Application is already installed.");
} else {
// Redirect to play store
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=Package name of your App B"));
startActivity(i);.
Log.i("Application is not currently installed.");
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}}
Hope i gave you an solution :)

MohanKumar
- 960
- 10
- 26
-
I do not wish to take the user to the play store. It has to be seamless. After the button tap, the user will only see an activity indicator. Downloading the package should happen in the background. Its ok if the user has to authorise the installation with a permission alert. – Babu Bhatt Apr 17 '19 at 08:03
-
First download the apk to a specific path to do it refer this link https://stackoverflow.com/questions/16117067/how-to-download-a-file-from-a-server-and-save-it-in-specific-folder-in-sd-card-i then open the apk from that specific path you stored using the below code 'Intent promptInstall = new Intent(Intent.ACTION_VIEW) .setDataAndType(Uri.parse("content:///path/to/your.apk"), "application/vnd.android.package-archive"); startActivity(promptInstall);' – MohanKumar Apr 17 '19 at 08:16