Home » Android » java – Check if app available on Android Market

java – Check if app available on Android Market

Posted by: admin June 15, 2020 Leave a comment

Questions:

Given an Android application’s id/package name, how can I check programatically if the application is available on the Android Market?

For example:

com.rovio.angrybirds is available, where as com.random.app.ibuilt is not

I am planning on having this check be performed either from an Android application or from a Java Servlet.

Thank you,

PS: I took a look at http://code.google.com/p/android-market-api/ , but I was wondering if there was any simpler way to checking

How to&Answers:

You could try to open the details page for the app – https://market.android.com/details?id=com.rovio.angrybirds.

If the app doesn’t exist, you get this:

enter image description here

It’s perhaps not ideal, but you should be able to parse the returned HTML to determine that the app doesn’t exist.

Answer:

Given an Android application’s id/package name, how can I check programatically if the application is available on the Android Market?

There is no documented and supported means to do this.

Answer:

While the html parsing solution by @RivieeaKid works, I found that this might be a more durable and correct solution. Please make sure to use the ‘https’ prefix (not plain ‘http’) to avoid redirects.

/**
 * Checks if an app with the specified package name is available on Google Play.
 * Must be invoked from a separate thread in Android.
 *
 * @param packageName the name of package, e.g. "com.domain.random_app"
 * @return {@code true} if available, {@code false} otherwise
 * @throws IOException if a network exception occurs
 */
private boolean availableOnGooglePlay(final String packageName)
        throws IOException
{
    final URL url = new URL("https://play.google.com/store/apps/details?id=" + packageName);
    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
    httpURLConnection.setRequestMethod("GET");
    httpURLConnection.connect();
    final int responseCode = httpURLConnection.getResponseCode();
    Log.d(TAG, "responseCode for " + packageName + ": " + responseCode);
    if(responseCode == HttpURLConnection.HTTP_OK) // code 200
    {
        return true;
    }
    else // this will be HttpURLConnection.HTTP_NOT_FOUND or code 404 if the package is not found
    {
        return false;
    }
}