How to restrict app to Android phones only

17,722

Solution 1

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.

Solution 2

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>

Solution 3

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

Share:
17,722

Related videos on Youtube

N Sharma
Author by

N Sharma

I have done masters in Advanced Software Engineering. I have worked on various technologies like Java, Android, Design patterns. My research area during my masters is revolving around the Recommendation algorithms that E-commerce websites are using in order to recommend the products to their customers on the basis of their preferences.

Updated on September 17, 2022

Comments

  • N Sharma
    N Sharma over 1 year

    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.

  • Simon Marquis
    Simon Marquis almost 10 years
    Arf, you are faster than me on this one ;)
  • N Sharma
    N Sharma almost 10 years
    large and xlarge are for 7 and 10 inch tablet right ?
  • CommonsWare
    CommonsWare almost 10 years
    @Williams: The official docs specify minimum sizes in dp for those buckets. Roughly speaking, large kicks in around 5" diagonal, while xlarge starts at 10" diagonal.
  • N Sharma
    N Sharma almost 10 years
    Nexus 5 comes in which category ?
  • CommonsWare
    CommonsWare almost 10 years
    @Williams: According to emirweb.com/ScreenDeviceStatistics.php it should be normal.
  • Ahmed Faisal
    Ahmed Faisal over 8 years
    Will this answer still work for modern day large phone which are 5+ inches diagonally?
  • CommonsWare
    CommonsWare over 8 years
    @Ahmed: This answer is not tied to a specific screen size.
  • Pär Nils Amsen
    Pär Nils Amsen about 7 years
    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!
  • Amit Garg
    Amit Garg almost 7 years
    This doesn't work for all smart phones, 5X, pixes, Galaxy will be unable to download. I've tried this in production.
  • Rahul Rastogi
    Rahul Rastogi almost 7 years
    Is above configuration working charm on play store download?
  • Mr. Nacho
    Mr. Nacho over 6 years
    Does using this will only allow installation of app in sim capable devices whether tablet, phablet or normal size phones?
  • baash05
    baash05 over 6 years
    Yes. no sim, no install. :) But it doesn't require the user to say yes to using their phone.
  • Aman Verma
    Aman Verma over 5 years
    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
  • CommonsWare
    CommonsWare over 5 years
    @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. 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.
  • Compaq LE2202x
    Compaq LE2202x over 5 years
    @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.
  • Display name
    Display name over 5 years
    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
  • Pär Nils Amsen
    Pär Nils Amsen over 5 years
    @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.
  • Bruce
    Bruce almost 3 years
    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
  • monchisan
    monchisan over 2 years
    @baash05 from the official docs 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.
  • baash05
    baash05 over 2 years
    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
    baash05 over 2 years
    I think the play store removes apps from your install options, if you don't have the required hardware.