简体   繁体   English

Android 应用程序将在 Play 商店发布新版本时自动更新

[英]Android Application will auto update when a new version is released on play store

I update the new version of my application in play store.我在 Play 商店中更新了我的应用程序的新版本。 Want to make auto update in those phone where the application is already installed.想要在已经安装了应用程序的手机中进行自动更新。 I did this work.我做了这项工作。

dependencies {
    compile 'org.jsoup:jsoup:1.10.2'
}

and in MainActivity I did this work-MainActivity我做了这项工作-

 public class MainActivity extends AppCompatActivity {

    String newVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new FetchAppVersionFromGooglePlayStore().execute();
    }

    class FetchAppVersionFromGooglePlayStore extends AsyncTask<String, Void, String> {

        protected String doInBackground(String... urls) {
            try {
                return
                        Jsoup.connect("https://play.google.com/store/apps/details?id=" + "com.directed.android.smartstart" + "&hl=en")
                        .timeout(10000)
                        .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 (Exception e) {
                return "";
            }
        }

        protected void onPostExecute(String string) {
            newVersion = string;
            Log.d("new Version", newVersion);
        }
    }
}

But, still not working.但是,仍然无法正常工作。 How can I solve this problem?我怎么解决这个问题?

I believe what you want is to support in-app updates.我相信您想要的是支持应用内更新。 As the official docs states, In-app updates shows a dialog to the user in case an update is available and it's the user's choice whether he/she wants to update it or not.正如官方文档所述,应用内更新会向用户显示一个对话框,以防有更新可用,并且用户可以选择是否要更新它。

This is how it looks like:这是它的样子:

在此处输入图像描述

I personally find it good because as an android developer, I want my users to stay updated considering privacy and security concerns.我个人觉得这很好,因为作为 android 开发人员,考虑到隐私和安全问题,我希望我的用户保持更新。 and it doesn't enforce user to update maintaining the UX.并且它不强制用户更新维护 UX。

This way you don't have to mess with JSOUP as it works with in-built AppUpdateManager .这样您就不必弄乱 JSOUP 了,因为它可以与内置的AppUpdateManager You should give it a read on the official docs: Support in-app updates .您应该阅读官方文档:支持应用内更新

EDIT: You can further set and check update priority evaluating the severity of update whether it's necessary.编辑:您可以进一步设置和检查更新优先级,评估更新的严重性是否有必要。 As official document states:正如官方文件所述:

The Google Play Developer API allows you to set the priority of each update. Google Play Developer API 允许您设置每次更新的优先级。 This allows your app to decide how strongly to recommend an update to the user.这允许您的应用决定向用户推荐更新的强度。 For example, consider the following strategy for setting update priority:例如,考虑以下设置更新优先级的策略:

Minor UI improvements: Low-priority update;较小的 UI 改进:低优先级更新; request neither a flexible nor immediate update.既不要求灵活更新,也不要求立即更新。

Performance improvements: Medium-priority update;性能改进:中优先级更新; request a flexible update.请求灵活更新。

Critical security update: High-priority update;关键安全更新:高优先级更新; require an immediate update.需要立即更新。

To determine priority, Google Play uses an integer value between 0 and 5, with > 0 being the default, and 5 being the highest priority.为了确定优先级,Google Play 使用介于 0 和 5 之间的 integer 值,> 0 是默认值,5 是最高优先级。 To set the priority for an update, use inAppUpdatePriority field under Edits.tracks.releases in the Google Play Developer API.要设置更新的优先级,请使用 Google Play Developer API 中 Edits.tracks.releases 下的inAppUpdatePriority字段。 Priority can only be set when rolling out a new release, and cannot be changed later.优先级只能在推出新版本时设置,以后不能更改。

Priority is relevant because it will change the frequency of the update dialog visible to user as bothering user to update every time for minor update is not a good UX.优先级是相关的,因为它会改变用户可见的更新对话框的频率,因为每次小更新都会打扰用户进行更新,这不是一个好的用户体验。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序从 Play 商店强制更新时,如何保持 android 应用程序始终登录 state? - How to keep android applications always be login state when application get force update from play store? 当api 24和api 25中提供新版本时,Android以编程方式更新应用程序 - Android programmatically update application when a new version is available in api 24 and api 25 在Play商店上更新新版本,这可能导致以前安装的应用在更新时崩溃 - updating new version on play store that would cause previously installed apps to crash on update 获取应用程序的 Play-store 版本 - Getting play-store version of the application 如何在Android上的Play商店上传我的应用程序的新版本之前测试升级sqlite数据库 - how to test upgrading sqlite database before uploading new version of my app on play store in android android-更新按钮未显示在Google Play商店中 - android - Update button is not displaying on Google Play Store 使用新项目更新Google Play上的应用(Android)吗? - Update app (Android) on Google play with new project? 什么时候释放“ SELECT…FOR UPDATE”锁? - When is `SELECT … FOR UPDATE` lock released? 通过Android Studio运行时,Android应用程序中的语言发生了更改,但从Play商店下载应用程序后,这些更改不起作用 - Language changes in Android Application take place when running through Android Studio but do not work when app is downloaded from play store 更新到新的Android材料版本失败 - Failed to update to the new Android Material version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM