简体   繁体   中英

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

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:

在此输入图像描述

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

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;
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM