1

I am not able to see the Google In-App Updates working in my application. Here is the way I have implemented my code, but it appUpdateInfo always returns UPDATE_NOT_AVAILABLE (1).

onCreate Method

appUpdateManager = AppUpdateManagerFactory.create(this)
        appUpdateManager.registerListener(this)
        val appUpdateInfoTask = appUpdateManager.appUpdateInfo

    appUpdateInfoTask.addOnSuccessListener {appUpdateInfo ->
        try {
            if(appUpdateInfoTask.isComplete){
                if (appUpdateInfo.updateAvailability() == UPDATE_AVAILABLE) {
                    ToastUtils.showShort("Update Available" + appUpdateInfo.isUpdateTypeAllowed(FLEXIBLE))
                    if(appUpdateInfo.isUpdateTypeAllowed(FLEXIBLE)){
                        ToastUtils.showShort("Flexi Update")
                        requestAppUpdate(appUpdateManager.appUpdateInfo.getResult(), FLEXIBLE)
                    }else if(appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE)){
                        ToastUtils.showShort("Immediate Update")
                        requestAppUpdate(appUpdateManager.appUpdateInfo.getResult(), IMMEDIATE)
                    }
                }
            }
        } catch (e: Exception) {
            Log.e("Update Exception", e.message)
        }
    }

onResume Method

override fun onResume() {
        super.onResume()
        val appUpdateInfoTask = appUpdateManager.appUpdateInfo
        appUpdateInfoTask.addOnCompleteListener {
            Log.e("Update Complete", "Complete")
        }
        appUpdateInfoTask.addOnSuccessListener {
            if(appUpdateInfoTask.isComplete){
                if (it.installStatus() == DOWNLOADED) {
                    showUpdateSnackbar()
                }
            }
        }
    }

onDestroy Method

override fun onDestroy() {
        super.onDestroy()
        appUpdateManager.unregisterListener(this)
    }

onActivityResult Method

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_TO_FETCH_UPDATES) {
            when (resultCode) {
                Activity.RESULT_OK -> {
                    ToastUtils.showShort("Access to Update Granted")
                }
                Activity.RESULT_CANCELED -> {
                    ToastUtils.showShort("Access to Update Cancelled")
                }
                ActivityResult.RESULT_IN_APP_UPDATE_FAILED -> {
                    ToastUtils.showShort("Access to Update Failed")
                }
            }
        }
    }

Key Points

  1. Uploaded my app on the internal test track with Android App Bundle Format
  2. App Update is available on the store(on internal track) when my code written above in onCreate returns UPDATE_NOT_AVAILABLE.
  3. I have uploaded the using Google Play Developers API, and have set the inAppUpdatePriority as 5

QUERIES:

  1. I have tried updating the app many times on the store and I can never see an update on my app via this code.WHY?
  2. How can I see actual FLEXIBLE or IMMEDIATE Update by testing from the Internal test track? Where is the way to set that configuration?
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143

1 Answers1

0

I have recently implemented in app date successfully so I think I may be able to help you.

I may suggest you to make some changes in your code and also you must follow the correct way of testing with internal app sharing.

Inside the try block in OnCreate Method you can use this

if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE){

   if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                appUpdateManager.startUpdateFlowForResult(
                appUpdateInfo,
                AppUpdateType.FLEXIBLE,
                this,
                REQUEST_CODE_TO_FETCH_UPDATES)
    } 
   else if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                appUpdateManager.startUpdateFlowForResult(
                appUpdateInfo,
                AppUpdateType.IMMEDIATE,
                this,
                REQUEST_CODE_TO_FETCH_UPDATES)
     }

  }

To test the in app update feature you must follow the following points-

  • You must make sure that the current app on your device is installed using an internal app sharing URL and the current app already supports in-app updates and also its version code must be lower than the updated version in Internal App Sharing.
  • If above all is fine, 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.
  • Now when you open the app you will find the update in your app.

    Or in simple way -

    Step 1- Just build your app with the app update features and upload it to the Internal App Testing in Play Console

    Step 2- Now go to the link obtained after uploading the app and install this version of your app from Play Store.

    Step 3- Now again build your app with a higher version code than the previous one and again upload it to the Internal App Testing in Play Console

    Step 4 - Now again go to the link obtained after uploading the app but now don't install this update just after going to Play Store page, press back and exit.

    Step 5 - Now open your previously installed app and you will find the app update in your app

Hope it helps you.

MrinmoyMk
  • 551
  • 7
  • 21
  • I don't think it will work @MrinmoyMk. My main problem is I am not seeing UPDATE_AVAILABLE. still I will give it a try. – Gaurav Arora May 06 '20 at 09:48
  • Please check the changes in the code that I made. I am using this way and it works. Please let me know if it does not work. Also to see the update follow the internal app sharing requirements if you don't follow it will not show any update – MrinmoyMk May 06 '20 at 13:14
  • I have recently worked on In-App Updates and published an article on it. Just copy-paste my code. It will work. Here is the link: https://medium.com/@sa159871/support-in-app-updates-in-android-a20ad11a4a80 – Shubham Agrawal Jul 19 '20 at 19:37