18

In my app, I'm recommending related apps, but only want to recommend them if they actually can be installed on the device (e.g. device in related apps' targeted countries, correct OS version, etc.). See https://developer.android.com/google/play/filters.html

  1. Is there any API that allows me to query if a given app I am recommending by linking to market://details?id=package_name can be installed on the local device?
  2. If not, I could manually store the other apps' requirements in my own app. But then, how do I determine items such as the country the users' Play Store is associated with?
UsAaR33
  • 3,536
  • 2
  • 34
  • 55
  • Would you consider as an option (and a very ugly workaround) launching a WebView within the client pointing to https://play.google.com/store/apps/details?id=package.name and see if the "Install" button is enabled or not by parsing the output HTML? In this way Google will do the check for you. – JohnUopini Jun 28 '14 at 13:14
  • This would require the user to log in though, right? – UsAaR33 Jun 29 '14 at 06:47

2 Answers2

11

Unfortunately, there is no API to compare an app with specific devices. The Play Store is it doing somehow internally.

So, the second approach is the way to go. The most common filters are

  • Country (since you can't retrieve the "play store country", use other approaches...)

    String locale = context.getResources().getConfiguration().locale.getCountry(); 
    // or if you are sure there is a SIM-card
    TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String countryCode = tm.getSimCountryIso();
    // or use country of current network (i.e. from 3G)
    String countryCode = tm.getNetworkCountryIso()
    
  • Android version

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
        // only for gingerbread and newer versions
    }
    
  • Screen size

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    

You may want to check other things like the available sensors (which you could do via getSensorList). To list them all would create a very long list and finding all APIs to find these things is mostly easy, so I won't list them all.

By checking country, version and screen size you should be safe with most of the apps.

Community
  • 1
  • 1
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
  • This doesn't quite work for Country. locale is user set, so that is not reliable. SIM country ISO may be a good predictor, but is not how the Play Store treats access. (http://forum.xda-developers.com/showthread.php?t=2169261) e.g. if I travel to country X and install a sim for country X, my Play Store access doesn't change to that of country X's. – UsAaR33 Jun 23 '14 at 21:56
  • 2
    Play Store grants access according to the logged-in users _account_ country. If you're using G+ sign in, you can [retrieve details about the currently signed in user](https://developers.google.com/+/mobile/android/people#retrieve_profile_information_for_a_signed_in_user), but that doesn't include locale info - there is [`Person.PlacesLived`](http://developer.android.com/reference/com/google/android/gms/plus/model/people/Person.PlacesLived.html) but that sounds like a maintenance nightmare. – Adam S Jun 23 '14 at 23:41
  • 3
    Additionally, just because a user lives in country X (and has that information on their G+ profile), doesn't mean their account is set to country X. – Adam S Jun 23 '14 at 23:42
  • @AdamS yes, there is no way to retrieve the users country stored in his account... But I want to show some ways to get the country, _if_ and _how_ OP uses it, I don't know. – Manuel Allenspach Jun 24 '14 at 06:18
2

Is there any API that allows me to query if a given app I am recommending by linking to market://details?id=package_name can be installed on the local device?

Yes, sort of, but the api/trick I'm thinking about may not fit your requirements at all.

It's an experimental Google feature, as far as I know it's for web applications only (not Android apps, although I suppose it might work with an Android web browser and your resulting application may not end up looking native), it requires your users to have a Google+ login (not just a gmail account), and you need to be manually whitelisted by Google in order to use it.

The idea is that once you login with Google+ on your (whitelisted) third party web site, you can click on the install button located on the third party web site and the third party web site will popup a window giving you a one-click install button to confirm the permissions and do a remote install for an over-the-air update.

As you can see from the url bar of the screenshot below, the popup window actually comes from the Google Play domain, so technically, it's just a simple trick that's meant to give the user the ability to install an application without leaving completely your web site.

Also, I want you to notice the current pull-down select box with the name of your device in it. You can't see it here, but the selection box contains all of the registered devices with your Google+ account, and it only shows black font for your device(s) that are compatible with the actual application in question.

screenshot of beta tunin radio web site with Google plus and Google Play integration

Now for the bad news. In this example, the web site belongs to TuneIn radio and the Android application belongs itself to TuneIn radio as well. I personally have no idea if this feature could be enabled for a web site listing Android applications that it doesn't own itself. That would be a question you'd have to ask Google.

Currently, this api is still just web only. This is an objection that the Google employees may raise when you ask them to whitelist your application.

Currently, TuneIn radio allows you to register devices with your Google+ account, but it doesn't show anything of what I saw in the presentation I attended. In the presentation I saw, there was no registration of devices required by the user, everything was done seamlessly once Google+ sign-in was associated with the account. So looking at the tunein.com radio web site itself may not be very useful to you.

And finally, I believe Google frowns upon other third party App stores, so before pleading your case to Google to try to get yourself included for the whitelist of this api. Make sure to carefully comply with the terms and services of the Google Play Store and be prepared to think about how Google would eventually benefit from allowing you (and others like you) to use this kind of feature.

Here is the slide deck on github (for some reason, the display of the slide deck itself no longer works for me). You need to contact either of those Google employees to get you whitelisted for this api. Their contact info/Google+ info is in the slide deck.

Please let us know of you progress. I'd be very interested to know if you can overcome any of the problems I've listed above.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49