2

I have gone through the steps mentioned here Support in-app updates. I have uploaded application to the play store to check app update feature. Below is my code snippet:

class MainActivity : AppCompatActivity() {

    val REQUEST_CODE_UPDATE = 1001

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setSupportActionBar(toolbar)

        fab.setOnClickListener { view ->
           Snackbar.make(view, "Checking for update", Snackbar.LENGTH_LONG)
                .show()
            checkForUpdate()
        }

    }


    override fun onResume() {
        super.onResume()

        val updateManager = AppUpdateManagerFactory.create(this)
        updateManager.appUpdateInfo
            .addOnSuccessListener {
                if (it.updateAvailability() ==
                    UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                    updateManager.startUpdateFlowForResult(
                        it,
                        IMMEDIATE,
                        this,
                        REQUEST_CODE_UPDATE)
                }
            }
    }
    fun checkForUpdate(){

        // Creates instance of the manager.
        val appUpdateManager = AppUpdateManagerFactory.create(this)

        // Checks that the platform will allow the specified type of update.
        appUpdateManager.appUpdateInfo.addOnSuccessListener {
            if (it.availableVersionCode() == UpdateAvailability.UPDATE_AVAILABLE &&
            it.isUpdateTypeAllowed(IMMEDIATE)) 
                      {
                    appUpdateManager.startUpdateFlowForResult(
                        it,
                        IMMEDIATE,
                        this,
                        REQUEST_CODE_UPDATE)

                }
            }

    }

    public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == REQUEST_CODE_UPDATE) {
            if (requestCode != RESULT_OK) {
                Log.e("System out", "Update flow failed! Result code: " + resultCode)
                // If the update is cancelled or fails,
                // you can request to start the update again.
            }
        }
    }
}

My Gradle file:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'

    implementation 'com.google.android.play:core:1.5.0'
}

When I debug below code, I above code, every time I am getting if (appUpdateInfo.availableVersionCode() == 0(UpdateAvailability.UNKNOWN)

Logs:

I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : requestUpdateInfo(com.inappupdate)
I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : requestUpdateInfo(com.inappupdate)
I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : Initiate binding to the service.
I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : Waiting to bind to the service.
I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.installservice.DevTriggeredUpdateService})
I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : linkToDeath
2019-05-09 16:11:23.534 22537-23035/com.inappupdate I/PlayCore: UID: [10280]  PID: [22537] OnRequestInstallCallback : onRequestInfo
I/PlayCore: UID: [10280]  PID: [22537] AppUpdateService : Unbind from service.
I/PlayCore: UID: [10280]  PID: [22537] OnRequestInstallCallback : onRequestInfo

So, if anyone can guide me on how I can resolve this error.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mehta
  • 1,228
  • 1
  • 9
  • 27
  • Stupid question, but can you see the app in the play store app? I'm guessing the play store has an exported service that the SDK is communicating with (I'm starting the same implementation but haven't gotten as far as you yet) – Kenny May 09 '19 at 12:05
  • @Kenny: yes I can see an application in the play store. "exported service that the SDK is communicating" not getting. – Mehta May 09 '19 at 12:30
  • @Mehta How did you resolve this error? – Kunal Jun 12 '19 at 11:21

1 Answers1

2

In this string:

(appUpdateInfo.availableVersionCode() == 0(UpdateAvailability.UNKNOWN)

you try to compare int(number of app version) with UpdateAvailability(0..3)

Right one is:

(appUpdateInfo.updateAvailability() == 0(UpdateAvailability.UNKNOWN)