Android获取Google Play商店应用版本 [英] Android get Google Play Store app version

查看:617
本文介绍了Android获取Google Play商店应用版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码获取Google Play商店应用的版本,但这导致我的应用挂起.请指定获取应用版本的另一种方法,或者指定如何使用此代码使应用无法挂起并成功运行.

I am using this code to get the Google Play Store app version but this is causing my app to hang. Please specify another way to get the app version or how I can use this code to make the app not hang and run successfully.

public class VersionChecker extends AsyncTask<String, String, String> {

    private String newVersion;

    @Override
    protected String doInBackground(String... params) {

        try {
            newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + "trai.gov.in.dnd" + "&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("div[itemprop=softwareVersion]")
                    .first()
                    .ownText();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return newVersion;
    }
}

这是我的代码,用于从asynctask获取应用版本

This is my code to get the app version from asynctask

VersionChecker versionChecker = new VersionChecker();
try {
    String appVersionName = BuildConfig.VERSION_NAME;
    String mLatestVersionName = versionChecker.execute().get();
    if (versionChecker.compareVersionNames(appVersionName, mLatestVersionName) == -1) {
        showAppUpdateDialog();
    }
} catch (InterruptedException | ExecutionException e) {
    e.printStackTrace();
}

推荐答案

只需替换您的代码

.get()
.select("div[itemprop=softwareVersion]")
.first()
.ownText();

                    

具有以下内容:

.get()
.select(".hAyfc .htlgb")
.get(3)
.ownText();

它将起作用..!

这篇关于Android获取Google Play商店应用版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆