0

I update the new version of my application in play store. 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-

 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?

samabcde
  • 6,988
  • 2
  • 25
  • 41
  • 1
    You should leave it to the users, whether they want automatic updates for an app or not. Forcing updates onto your users, like you want to, is not nice. – Ridcully Jun 10 '20 at 06:11
  • But, how do user know there is a new version available on play store? Will application inform users automatically without doing any work in my android code? – Imtiaz Riad Jun 10 '20 at 06:20
  • @ImtiazRiad Yes. The Google Play store (and afaik other stores like Amazon, Huawei, Samsung Galary) roll out updates over a certain time period (hours or days) to all users. If the user enabled auto update for all their apps, the app gets updated automatically. Otherwise they get a notification reading something like "XX apps are ready to update". – Alexander Hoffmann Jun 10 '20 at 06:44
  • great. Thank you for informing me. I didn't know. – Imtiaz Riad Jun 10 '20 at 09:10

1 Answers1

1

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:

enter image description here

I personally find it good because as an android developer, I want my users to stay updated considering privacy and security concerns. and it doesn't enforce user to update maintaining the UX.

This way you don't have to mess with JSOUP as it works with in-built 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. 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; 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. To set the priority for an update, use inAppUpdatePriority field under Edits.tracks.releases in the Google Play Developer API. 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.

Lalit Fauzdar
  • 5,953
  • 2
  • 26
  • 50
  • can you please help me where to set this `inAppUpdatePriority` priority. because I don't find any way to set it from the application side. – Harshad Prajapati May 31 '21 at 18:30
  • @HarshadPrajapati Look at [these answers](https://stackoverflow.com/q/61115215/8244632). You can also look at [this thread](https://issuetracker.google.com/issues/133299031?pli=1#comment14) for some solution. It can only be done through APIs for now. From the application side, [this library](https://github.com/Triple-T/gradle-play-publisher) can help – Lalit Fauzdar May 31 '21 at 18:52