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

后端 未结 6 840
半阙折子戏
半阙折子戏 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:51

    You can do this with the Google Play Developer API but it looks pretty painful.

    https://developers.google.com/android-publisher/edits/overview

    https://github.com/googlesamples/android-play-publisher-api/blob/master/v2/java/src/com/google/play/developerapi/samples/ListApks.java

    0 讨论(0)
  • 2020-12-29 03:55

    With "beta" or "staging" in your app version name, you can get it with getPackageInfo() and check with a Regex or indexOf

    context.packageManager.getPackageInfo(context.packageName, 0).versionName.indexOf("beta") >= 0
    
    0 讨论(0)
  • 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();
    }
    
    0 讨论(0)
  • It's currently not possible to detect if the app was installed from either the Beta or Production Track on the Play Store.

    Assuming your app will be connecting to an API that you own - What you can do is let the API determine if the App is a Beta or Prod App. For example store the app version number(s) that are considered a Prod app on the API, when the app connects to the API it passes it's version number to the API and the API returns a response with whether it is Prod (The version matches one it has stored) or Beta App (it's does not match one it has stored).

    There are 2 Limitations to this though:

    1. You will need to update the mobile app version number(s) on your API when the app is ready to go to production.
    2. Mobile apps will be determined by their version number not what Track they are on in Play Store.

    If you're happy with these 2 limitations then you will only have 1 APK and a means to determine if your app is Prod or Beta.

    0 讨论(0)
  • 2020-12-29 04:05

    You can add a string in your resources, called 'VERSION' , and give it the appropriate value. From your app, you can check that ID and do whatever is required

    0 讨论(0)
  • 2020-12-29 04:06

    If your application's version name (android:versionName) always contains the string "beta" for beta releases, you can retrieve the package name at runtime, and check that.

    Use the getPackageInfo() method to retrieve a PackageInfo object which has a versionName String field.

    Another approach would be to use the android:versionCode. For example, you could decide that your beta releases always have an odd version code, and production releases always have an even one. You could use getPackageInfo() to retrieve the version code and make your determination based on that.

    0 讨论(0)
提交回复
热议问题