I am using this code to get the Google Play Store app version but this is causing my app to hang. Please specify another way to get the app version or how I can use this code to
It seems you use the "app-version" shown on the Google Play Store website to trigger an "update popup" to your users and notify when a new version is available. First of all, Google Play Store website is changing often, so that's not very reliable as your app might not be able to "parse/handle" those changes. If you want to keep that approach, some other answers already explained how to parse the right HTML tag and how to do in the background correctly. Keep in mind your app will be still responsible for the "parsing", eventually you would do the parsing remotely on a web-server, and expose to your app a stable API endpoint to retrieve the "latest-version" of your own app. If you do not want to bother with parsing HTML tags or host your own API, there are third-party APIs that can do that for you. We provide one such API here: https://42matters.com/docs/app-market-data/android/apps/lookup (it returns a JSON object with the latest "version name" of the app).
You could also use https://github.com/danielemaddaluno/Android-Update-Checker to not implement your own code, under the hood it does more or less the same as you do.
Personally I would use a remote service like Firebase Remote Config https://firebase.google.com/docs/remote-config or a simple JSON file hosted on your website specifying the latest published version of your app (just remember to change it once the update of your app is really published on Google Play, nowadays it might take a while). Also, I would rather use the "versionCode" as explained here: https://developer.android.com/studio/publish/versioning With this approach you could "trigger" the update when you want, more control on your side (especially in case you want to revert the "Please update" message, useful if you find a bug in the latest version you published)