Is it possible to detect that an android app is either a beta version or production version?

后端 未结 6 873
半阙折子戏
半阙折子戏 2020-12-29 03:29

We use beta staging in google play store. For app side force update functionality we want to detect if our app is either coming from the beta stage or the production stage o

6条回答
  •  庸人自扰
    2020-12-29 03:58

    Assuming the same apk is typically promoted from Beta to Production, the answer by Dizzy suggesting that a call out to some external API is required is the way to go.

    However, rather than setting up and hitting your own back-end API, you can just use an android HttpURLConnnection to check the Google Play store details page for your own app id.

    If the current user is enrolled in Beta, the app name is presented as "App Name (Beta)".

    A little further down the page it will also say "You're a beta tester for this app. Awesome!"

    The page contains a single button labelled either "Install", "Update" or "Installed", from which you can determine whether or not the user has the latest version

    On the same page your app can also look up the last production Updated date, and latest production version name.

    Sample Java code for how you might implement this below:

    boolean isBeta = false;
    URL url = new URL("https://play.google.com/sore/apps/details?id=com.example.app");
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
      InputStream in = new BufferedInputStream(urlConnection.getInputStream());
      Scanner scanner = new Scanner(in);
      isBeta = (scanner.findWithinHorizon("\\s\\(Beta\\)", 650000) != null);
    } finally {
      urlConnection.disconnect();
    }
    

提交回复
热议问题