'Android Studio Update app from google drive link no Google Play Store

I would like to be able to install updates on my app from new version APK files. I would like to upload it to google Drive and be able to install from here. I have already created a script for the App to check if there is a new version. Now I just need it to actually do the update from the APK within the app.

Here is what I have once it detects a new version.

if (Integer.parseInt(updateAvailable) >  BuildConfig.VERSION_CODE) {
            new AlertDialog.Builder(Login.this)
                    .setTitle("Update")
                    .setMessage("New version is available")
                    .setPositiveButton("Update Now", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            
//Required code to install APK from link

                        }
                    })
                    .setNegativeButton("Later", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    })
                    .show();

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source