如何以编程方式获取实时应用程序?

发布于 2025-02-06 10:24:57 字数 1756 浏览 3 评论 0原文

最初,要以编程方式获取实时应用程序版本,我正在使用以下片段

 try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + appPackageName + "&hl=en")
                    .timeout(30000)
                    .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(".hAyfc .htlgb")
                    .get(7)
                    .ownText();
        } catch (IOException e) {
            e.printStackTrace();
        }

,但是在2022年5月底,该片段开始抛出异常。有人有类似的问题吗? 任何修复程序都是非常欢迎的。

***解决方案 ***

Google现在为此提供了官方解决方案

使用 appupdatemanager

来自官方文档

检查是否有更新可用性

在请求更新之前,您需要先检查一个 可用于您的应用。要检查更新,请使用appupdatemanager, 如下所示:

  //创建管理器的实例。 
 appupdatemanager appupdatemanager = appupdatemanagerfactory.create(context);
    
//返回您用于检查更新的意图对象。
任务< appupdateinfo> appupdateInfotask = appupdatemanager.getAppupDateInfo();
    
//检查平台是否允许指定的更新类型。 appupdateInfotask.addonSuccessListener(appupdateinfo-> {
        if(appupdateinfo.updateavailability()== updateavailability.update_available
              //要进行灵活的更新,请使用appupdatetype.flexible
              && appupdateinfo.isupdateTypeAllowed(appupdatetype.immediate)){
                  //请求更新。
        }}); 
 

结果包含更新可用性状态。如果更新是 可用并允许更新,还返回的appupdateinfo 包含启动更新的意图。请参阅下一节 开始更新。

如果已经进行了应用内更新,则结果也将 报告过程内更新的状态。

这对我有用。希望它有帮助!

Initially, to fetch the live app version programmatically I was using the following snippet

 try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + appPackageName + "&hl=en")
                    .timeout(30000)
                    .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(".hAyfc .htlgb")
                    .get(7)
                    .ownText();
        } catch (IOException e) {
            e.printStackTrace();
        }

But at the end of May 2022, this snippet started throwing exceptions. Is anyone having a similar issue?
Any fixes are very welcome.

***Solution***

Google Provides an official solution for this now

Use AppUpdateManager

from the official documentation

Check for update availability

Before requesting an update, you need to first check if one is
available for your app. To check for an update, use AppUpdateManager,
as shown below:

// Creates instance of the manager. 
 AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(context);
    
// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
    
// Checks that the platform will allow the specified type of update. appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
              // For a flexible update, use AppUpdateType.FLEXIBLE
              && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                  // Request the update.
        } }); 

The result contains the update availability status. If an update is
available and the update is allowed, the returned AppUpdateInfo also
contains an intent to start the update. See the next section for how
to start the update.

If an in-app update is already in progress, the result will also
report the status of the in-progress update.

This worked for me. Hope it helps !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我家小可爱 2025-02-13 10:24:57

是的,Google更新了他们的Play商店网站,该解决方案不再可行。 DOM结构已更改,应用程序版本并非隐藏在动态加载的模态后面。我目前正在尝试找到一个新的解决方案。

Yes, google updated their play store website, that solution no longer works. The dom structure has changed, app versions are no hidden behind a modal that is dynamically loaded. I am currently in the process of trying to find a new solution as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文