21

Hello I am targeting users to Android phones only. I want to restrict the app to install on Android phones ony not on phablets and tablets.

What are the configuration do I need to apply in AndroidManifest.xml so that Google Play app wont show the app in the table and phablets.

Thanks in advance.

N Sharma
  • 33,489
  • 95
  • 256
  • 444
  • I think these 2 posts will solve your problem. [Manifest and supported devices showed in android market][1] [Android Manifest Restrict To Tablets][2] [1]: http://stackoverflow.com/questions/8225580/manifest-and-supported-devices-showed-in-android-market [2]: http://stackoverflow.com/questions/7649558/android-manifest-restrict-to-tablets –  Aug 10 '14 at 16:31

4 Answers4

27

Because of the high densities of new devices such as Nexus 5X, Nexus 6P and the Samsung Galaxy S6 we had to adapt the manifest as following:

<compatible-screens>
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" />
    <screen android:screenSize="small" android:screenDensity="420" />
    <screen android:screenSize="small" android:screenDensity="480" />
    <screen android:screenSize="small" android:screenDensity="560" />
    <screen android:screenSize="small" android:screenDensity="640" />
    <screen android:screenSize="normal" android:screenDensity="ldpi" />
    <screen android:screenSize="normal" android:screenDensity="mdpi" />
    <screen android:screenSize="normal" android:screenDensity="hdpi" />
    <screen android:screenSize="normal" android:screenDensity="xhdpi" />
    <screen android:screenSize="normal" android:screenDensity="420" />
    <screen android:screenSize="normal" android:screenDensity="480" />
    <screen android:screenSize="normal" android:screenDensity="560" />
    <screen android:screenSize="normal" android:screenDensity="640" />
    <screen android:screenSize="large" android:screenDensity="ldpi" />
    <screen android:screenSize="large" android:screenDensity="mdpi" />
    <screen android:screenSize="large" android:screenDensity="hdpi" />
    <screen android:screenSize="large" android:screenDensity="xhdpi" />
    <screen android:screenSize="large" android:screenDensity="420" />
    <screen android:screenSize="large" android:screenDensity="480" />
    <screen android:screenSize="large" android:screenDensity="560" />
    <screen android:screenSize="large" android:screenDensity="640" />
</compatible-screens>
Display name
  • 2,697
  • 2
  • 31
  • 49
  • 3
    Have you tested this in prod? We were using the "old" answer above up until last month when we saw that devices as Pixel and the new Samsung S8 weren't supported Did a quick removal of it, but now we support tablets which isn't really what we want. This feels messy! – Pär Nils Amsen May 11 '17 at 12:29
  • Is above configuration working charm on play store download? – Rahul Rastogi Jul 25 '17 at 04:59
  • @PärNilsAmsen did you get your answer from @Displayname? I'm asking the same thing, especially now in 2018 where there are more bigger density phones released like Pixel 3 and Pixel 3 Excel. – Compaq LE2202x Dec 20 '18 at 05:30
  • Sorry for the late reply, I don't use the above filter in production at the moment, so unfortunately I don't know how this behaves for new devices with bigger screens – Display name Dec 20 '18 at 11:14
  • 1
    @CompaqLE2202x Late reply, but in the end I just deleted the whole `compatible-screens` block and I would advise against using it for excluding tablets. Seriously, don't do it. We caught the filter in time, it's filtering a _lot_ of devices that we wanted. Haven't had a single problem since it got removed. Instead we are using the `android.hardware.telephony` solution to filter out 99% of tablets and other non-smartphone devices, has worked flawlessly. – Pär Nils Amsen Jan 15 '19 at 14:41
  • yes, apparently pixel 3, 3a, 4, 4a, 5 are on screen density of 400 and 440, which are not supported values in compatible-screens and I couldn't find any workaround for this so we are out of luck. Better to use android.hardware.telephony like @PärNilsAmsen mentioned – Bruce May 26 '21 at 04:13
20

An alternative is to test of the feature android.hardware.telephony

<uses-feature android:name="android.hardware.telephony" android:required="true" />

This would limit the app to phones.. of course phablets would be included in that, but it would be (IMHO) a better solution than the ever changing screen resolution approach..

baash05
  • 4,394
  • 11
  • 59
  • 97
  • 1
    Does using this will only allow installation of app in sim capable devices whether tablet, phablet or normal size phones? – Mr. Nacho Jan 05 '18 at 08:03
  • 1
    Yes. no sim, no install. :) But it doesn't require the user to say yes to using their phone. – baash05 Jan 24 '18 at 05:27
  • @baash05 from the [official docs](https://developer.android.com/guide/topics/manifest/uses-feature-element) it says: ---- When you declare android:required="true" for a feature, you are specifying that the application cannot function, or is not designed to function, when the specified feature is not present on the device. When you declare android:required="false" for a feature, it means that the application prefers to use the feature if present on the device, but that it is designed to function without the specified feature, if necessary. – monchisan Oct 25 '21 at 15:40
  • Right.. So the android:required=true would indicate "that the application cannot function". Isn't that what the OP wanted.. Only work on phone? – baash05 Oct 26 '21 at 20:38
  • I think the play store removes apps from your install options, if you don't have the required hardware. – baash05 Oct 26 '21 at 20:42
  • This works great, and I have confirmed that it still runs on an Android Emulator phone. – Justin Oct 06 '22 at 17:03
10

Quoting the documentation:

Because the system generally scales applications to fit larger screens well, you shouldn't need to filter your application from larger screens. As long as you follow the Best Practices for Screen Independence, your application should work well on larger screens such as tablets. However, you might discover that your application can't scale up well or perhaps you've decided to publish two versions of your application for different screen configurations. In such a case, you can use the <compatible-screens> element to manage the distribution of your application based on combinations of screen size and density. External services such as Google Play use this information to apply filtering to your application, so that only devices that have a screen configuration with which you declare compatibility can download your application.

Bear in mind that <compatible-screens> requires you to whitelist every screen size and density that you are supporting (and we get a new density every year or so), and you are limited to the classic screen size buckets (small, normal, large, xlarge). The documentation's sample is missing some densities:

<compatible-screens>
    <!-- all small size screens -->
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" />
    <!-- all normal size screens -->
    <screen android:screenSize="normal" android:screenDensity="ldpi" />
    <screen android:screenSize="normal" android:screenDensity="mdpi" />
    <screen android:screenSize="normal" android:screenDensity="hdpi" />
    <screen android:screenSize="normal" android:screenDensity="xhdpi" />
</compatible-screens>

You will need to add additional elements if are willing to support tvdpi, xxhdpi, and xxxhdpi devices.

Quoting the documentation for <compatible-screens>:

Caution: Normally, you should not use this manifest element. Using this element can dramatically reduce the potential user base for your application, by not allowing users to install your application if they have a device with a screen configuration that you have not listed. You should use it only as a last resort, when the application absolutely does not work with specific screen configurations. Instead of using this element, you should follow the guide to Supporting Multiple Screens to provide scalable support for multiple screens using alternative layouts and bitmaps for different screen sizes and densities.

And bear in mind that marketing terms like "phablet" is ill-defined, and so your app may wind up shipping on some devices that you happen to think is a phablet or that somebody else thinks is a phablet.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Arf, you are faster than me on this one ;) – Simon Marquis Aug 10 '14 at 16:25
  • large and xlarge are for 7 and 10 inch tablet right ? – N Sharma Aug 10 '14 at 16:26
  • 2
    @Williams: The [official docs](http://developer.android.com/guide/practices/screens_support.html#range) specify minimum sizes in `dp` for those buckets. Roughly speaking, `large` kicks in around 5" diagonal, while `xlarge` starts at 10" diagonal. – CommonsWare Aug 10 '14 at 16:28
  • Nexus 5 comes in which category ? – N Sharma Aug 10 '14 at 16:30
  • @Williams: According to http://www.emirweb.com/ScreenDeviceStatistics.php it should be `normal`. – CommonsWare Aug 10 '14 at 16:32
  • Will this answer still work for modern day large phone which are 5+ inches diagonally? – Ahmed Faisal Oct 27 '15 at 14:45
  • @Ahmed: This answer is not tied to a specific screen size. – CommonsWare Oct 27 '15 at 14:57
  • I have set the screensize to small and normal. And screen density to ldpi, mdpi ,hdpi xhdpi, 640, 560, 480, 420, 360, 280 for both small and normal size. I want to restrict all the Tablets. But when i published my app to playstore. My app (Huawei nova 3i) isn't compatible with this version. So when i commented the compatible screen and publish it the error disappear. What was the Problem? Device catalog showing the device as supported. Another phone huawei nova 3i isn't supported. @CommonsWare – Aman Verma Nov 02 '18 at 13:09
  • @AmanVerma: You would need to examine `Configuration` to see what that device claims its screen density is. [It appears to have an actual density of 409dpi](https://www.gsmarena.com/huawei_p_smart+_(nova_3i)-9272.php). Perhaps they chose some density value that is not covered in your list. Or, possibly, since the screen size is 6.3", they chose to have it be a `large` screen size. – CommonsWare Nov 02 '18 at 22:10
0

It really depends on what your are thinking about phone/phablets.

There is an official guide that will explain a lot better than me, but essentially, you could do the following to restrict your app to handset devices only.

AndroidManifest.xml

<manifest ... >
    <compatible-screens>
        <!-- all small size screens -->
        <screen android:screenSize="small" android:screenDensity="ldpi" />
        <screen android:screenSize="small" android:screenDensity="mdpi" />
        <screen android:screenSize="small" android:screenDensity="hdpi" />
        <screen android:screenSize="small" android:screenDensity="xhdpi" />
        <!-- all normal size screens -->
        <screen android:screenSize="normal" android:screenDensity="ldpi" />
        <screen android:screenSize="normal" android:screenDensity="mdpi" />
        <screen android:screenSize="normal" android:screenDensity="hdpi" />
        <screen android:screenSize="normal" android:screenDensity="xhdpi" />
    </compatible-screens>
    ...
    <application ... >
        ...
    <application>
</manifest>
Simon Marquis
  • 7,248
  • 1
  • 28
  • 43
  • This doesn't work for all smart phones, 5X, pixes, Galaxy will be unable to download. I've tried this in production. – Amit Garg Jul 12 '17 at 14:12