在后台查看Play商店以确定是否可以在设备上下载应用程序

时间:2013-06-02 16:10:13

标签: android google-play

我知道我可以使用网址链接到Play商店:

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

我喜欢做的是在后台“ping”此网址,并确定该应用是否实际可用,然后,我可以根据需要修改我的用户界面。

2 个答案:

答案 0 :(得分:6)

我们假设,如果应用不可用,则http://play.google.com/store/apps/details?id=<package_name>下的页面包含单词error-section。如果应用程序可用,则不包含此单词。

对该网址进行HTTP GET并搜索error-section

  • error-section - 您的应用可用。
  • 否则,它不可用。

像这样:

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

答案 1 :(得分:2)

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

}

我尝试了正确的&amp;如果应用程序不可用,假包裹及其提供的错误请求会响应积极的(成功200代码),如果应用程序在那里..所以plz检查一旦它可能会帮助你。

android 2.2&amp; app min req 2.3

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