79516921

Date: 2025-03-18 09:41:28
Score: 0.5
Natty:
Report link

I have the same issue. I need to know if the new version of the app is published when I publish the app from the developer console. I have to do some automation. Unfortunately, there is no Official API to fetch the live app version for Android. I use Unity and I need to work in Unity Editor. AppUpdateManager from Android only works on Android Builds.

I solved this issue currently, but it might be changed in the future. It takes the latest version from the App Store and Play Store. You need to have Selenium.WebDriver NuGet Package for this to work. You can use this NuGet Package to install it. Also, you need to pass something like “com.company.project” to the methods below to work.

You have to download ChromeDriver for Windows. Extract the .zip file. Then copy and paste .exe into your project somewhere. In this way, you don’t have to use Selenium-Manager to automatically download the ChromeDriver. You would need to put Selenium-Manager in your Environment PATH and in your Unity Editor tools directory for it. Giving the ChromeDriver path much more convenient and easier.

private static void GetLatestVersionFromAppStore(string bundleId, Action<string> onCompleted)
{
    UnityWebRequest request = UnityWebRequest.Get($"https://itunes.apple.com/lookup?bundleId={bundleId}");
    
    request.SendWebRequest().completed += operation =>
    {
        if (request.result != UnityWebRequest.Result.Success)
        {
            onCompleted?.Invoke(string.Empty);
            return;
        }
        
        string json = request.downloadHandler.text;
        var parsedJson = JsonUtility.FromJson<AppStoreResponse>(json);
        onCompleted?.Invoke(parsedJson.results.Length > 0 ? parsedJson.results[0].version : string.Empty);
        request.Dispose();
    };
}

private static string GetLatestVersionFromPlayStore(string packageName)
{
    string url = $"https://play.google.com/store/apps/details?id={packageName}&hl=en";
    var options = new ChromeOptions();
    options.AddArgument("--headless");

    string[] guids = AssetDatabase.FindAssets("chromedriver t:DefaultAsset");

    string chromeDriverPath;
    if (guids.Length > 0)
        chromeDriverPath =
            AssetDatabase.GUIDToAssetPath(guids.Find(x => AssetDatabase.GUIDToAssetPath(x).Contains(".exe")));
    else
        chromeDriverPath = string.Empty;

    using (var driver = new ChromeDriver(chromeDriverPath, options))
    {
        driver.Navigate().GoToUrl(url);
        
        var button = driver.FindElement(By.XPath("//button[i[contains(@class, 'google-material-icons') and text()='arrow_forward']]"));
        button.Click();

        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        
        var isPageLoaded = wait.Until(drv =>
        {
            ReadOnlyCollection<IWebElement> webElements = drv.FindElements(By.ClassName("G1zzid"));
            
            bool areAllElementsDisplayed = webElements.All(element => element.Displayed);
            
            return areAllElementsDisplayed && (bool)((IJavaScriptExecutor)drv).ExecuteScript(
                "return document.readyState == 'complete'");
        });

        var upperElements = driver.FindElements(By.ClassName("q078ud"));
        var lowerElements = driver.FindElements(By.ClassName("reAt0"));
        
        Dictionary<string, string> elements = new Dictionary<string, string>();

        for (int i = 0; i < upperElements.Count; i++)
            elements[upperElements[i].Text] = lowerElements[i].Text;
        
        return elements.GetValueOrDefault("Version", string.Empty);
    }
}
Reasons:
  • Blacklisted phrase (1): I have to do
  • Blacklisted phrase (0.5): I need
  • Blacklisted phrase (1): I have the same issue
  • Whitelisted phrase (-2): I solved
  • Whitelisted phrase (-1.5): You can use
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same issue
  • Low reputation (0.5):
Posted by: DeathPro