获取在playstore中运行的最新版本的android应用程序以请求更新

时间:2018-04-06 06:48:51

标签: java android jsoup

我一直在为用户b实现android app update,使用jsoup库检测在playstore中运行的最新应用程序。但最近它在我的应用程序中发生了一些崩溃。所以不得不删除它。因此,想知道是否有人可以阐明如何使用不同的策略实现同样的目标。

Old coe在下面: -

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

     @Override
     protected void onPreExecute() {
        super.onPreExecute();
     }

     @Override
     protected void onPostExecute(String latestversion) {
        super.onPostExecute(latestversion);
        PackageManager pm = getPackageManager();
        PackageInfo pInfo = null;
        try {
            pInfo = pm.getPackageInfo(getPackageName(), 0);

        } catch (PackageManager.NameNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String currentVersion = pInfo.versionName;
        if (!currentVersion.equals(latestversion)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(SplashActivity.this);
            builder.setTitle("A New Update is Available");
            builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse
                            ("market://details?id=" + getPackageName())));

                    dialog.dismiss();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    navigatetoMain();
                }
            });

            builder.setCancelable(false);
            dialog = builder.show();
        }else{
            navigatetoMain();
        }

    }
    @Override
    protected String doInBackground(String... params) {
        String newVersion="";
        try {
            doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + params[0] + "&hl=en").get();
               Elements element= doc.select("div[itemprop=softwareVersion]");
            newVersion= element.first().text();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return newVersion;
    }
}

private void checkAppversion() {
    new VersionChecker().execute(getPackageName());
}

0 个答案:

没有答案