[英]How to get the current app version of Android Play Store?
我檢查了谷歌或堆棧溢出的當前信息。 但是現在存在的代碼不適用於我的項目。
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
這是我測試版本的代碼。 有誰知道如何以除此之外的任何方式獲取當前 Android 應用程序版本的 Play 商店嗎?
我的項目正在使用 Retrofit 2 在存儲庫文件中異步運行 function。
如果您想知道 Google Play 中可用的版本,以便在有新更新可用時通知用戶。 建議使用 應用內更新 API
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)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.