Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if app available on Android Market

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

like image 634
Ares Avatar asked Sep 22 '11 14:09

Ares


3 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.

like image 157
RivieraKid Avatar answered Nov 09 '22 14:11

RivieraKid


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.

like image 31
CommonsWare Avatar answered Nov 09 '22 12:11

CommonsWare


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;
    }
}
like image 29
Nearchos Avatar answered Nov 09 '22 13:11

Nearchos