Reputation: 31
I checked the current information on google or stack overflow. But the codes that exist now don't apply to my project.
try {
val curVersion: String = "1.0.5"
var newVersion: String? = curVersion
newVersion =
Jsoup.connect("https://play.google.com/store/apps/details?id=" + "com.lsn.lsn_communication_app")
.timeout(3000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText()
if((curVersion) == (newVersion)){
storeVersion = "1.0.5"
}else{
storeVersion = "1.0.0"
}
} catch (e: Exception) {
e.printStackTrace()
storeVersion = ""
}
return storeVersion
This is my code to test the version. Does anyone know how to get the current Android app version of the Play Store in any way other than this?
My project is running a function asynchronously in a repository file using Retrofit 2.
Upvotes: 1
Views: 5158
Reputation: 329
val appUpdateManager = AppUpdateManagerFactory.create(context)
// Returns an intent object that you use to check for an update.
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// This example applies an immediate update. To apply a flexible update
// instead, pass in AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
) {
// Request the update.
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
AppUpdateType.IMMEDIATE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE)
}
}
Upvotes: 0
Reputation: 303
If you want to know the version available in Google Play for the purpose of informing the user when a new update is available. It is kindly recommended to use the in-app updates API
Upvotes: 1