Update Checker API

The American App Hub does not automatically update apps or notify users when updates are available. However, you may use the following code to detect updates.

API

Include the following code in your application:

    val updateChecker = UpdateChecker(context)
    val updateAvailable: Boolean? = updateChecker.updateAvailable()
    if (updateAvailable == true){
        // TODO: obtain the user's permission to open the app hub
        val intent = Intent(
            Intent.ACTION_VIEW,
            Uri.parse("https://americanapphub.com/apps/?id=${context.packageName}")
        )
        startActivity(intent)
    } else {
        // TODO: do something here
    }

Android Manifest

    <uses-permission android:name="com.lf.hub.ACCESS_UPDATE_STATE" />
    <queries>
        <package android:name="com.lf.hub" />
    </queries>

UpdateChecker.kt

    import android.content.Context
    import androidx.core.net.toUri

    class UpdateChecker(private val context: Context) {

        private val providerUri = "content://com.lf.hub.update".toUri()

        fun updateAvailable(): Boolean? {
            return try {
                val bundle = context.contentResolver.call(
                    providerUri,
                    "checkUpdates",
                    null,
                    null
                )
                if (bundle?.containsKey("updateAvailable") == true) {
                    bundle.getBoolean("updateAvailable")
                } else {
                    null
                }
            } catch (_: Exception) {
                null
            }
        }

    }