Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In background check the Play Store to determine if an app is available to download on the device

I know I can link to the Play Store with the URL:

market://details?id=com.example.appname

What I would love to do is 'ping' this URL in the background, and determine if the app is actually available, then, I can modify my UI as appropriate.

like image 215
Booger Avatar asked Jun 02 '13 16:06

Booger


2 Answers

Let's assume that, if app is unavailable, the page under http://play.google.com/store/apps/details?id=<package_name> contains, for example, word error-section. If app is available, it does not contain this word.

Make HTTP GET to that URL and search for error-section.

  • No error-section - your app is available.
  • Otherwise, it's unavailable.

Like this:

final HttpClient client = new DefaultHttpClient();  
final String getURL = "http://play.google.com/store/apps/details?id=<package_name>";
final HttpGet get = new HttpGet(getURL);
final HttpResponse responseGet = client.execute(get);  
final HttpEntity resEntityGet = responseGet.getEntity();  
if (resEntityGet != null) 
{  
    final String response = EntityUtils.toString(resEntityGet);
    if (response.indexOf("error-section") == -1)
    {
        // available
    }
    else
    {
        // unavailable
    }
}
like image 195
Adam Stelmaszczyk Avatar answered Nov 24 '22 00:11

Adam Stelmaszczyk


private class URLTest extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        try {
            try {
                HttpClient httpclient = new DefaultHttpClient();
                String strurl = "https://play.google.com/store/apps/details?id=com.rovio.angrybirdsstarwars.ads.iap";
                // String strurl =
                // "https://play.google.com/store/apps/details?id=com.rovio.angrybirdsstarwars.ads.iaptest";
                // //fake packagename append with "test"
                HttpGet httpget = new HttpGet(strurl);
                HttpResponse httpresp = httpclient.execute(httpget);
                if (httpresp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    Log.e("Found", "YES");
                } else if (httpresp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                    Log.e("Found", "NO");
                }

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } catch (Exception e) {
            Log.e("", "");
        }
        return null;
    }

}

i tried with correct & fake packages and its giving bad request responze if the app not available & positive(success 200 code) if app is there..so plz check it once it might help u.

android 2.2 & app min req 2.3

Correct URL 200 Response Success Resultfake url. app url which is nt available on play store Failure result 404

like image 36
user1140237 Avatar answered Nov 23 '22 23:11

user1140237