How to restrict app to Android phones only
Asked Answered
R

4

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.

Relinquish answered 10/8, 2014 at 16:14 Comment(1)
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]: #8226080 [2]: #7650058Gilpin
L
11

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.

Linebreeding answered 10/8, 2014 at 16:22 Comment(9)
Arf, you are faster than me on this one ;)Knudson
large and xlarge are for 7 and 10 inch tablet right ?Relinquish
@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.Linebreeding
Nexus 5 comes in which category ?Relinquish
@Williams: According to emirweb.com/ScreenDeviceStatistics.php it should be normal.Linebreeding
Will this answer still work for modern day large phone which are 5+ inches diagonally?Drinker
@Ahmed: This answer is not tied to a specific screen size.Linebreeding
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. @LinebreedingSafko
@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.Linebreeding
G
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>
Grillroom answered 18/12, 2015 at 10:50 Comment(6)
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!Pileum
Is above configuration working charm on play store download?Ornithology
@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.Glidewell
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 screensGrillroom
@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.Pileum
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 mentionedReeher
S
21

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

Somatotype answered 25/6, 2017 at 10:16 Comment(6)
Does using this will only allow installation of app in sim capable devices whether tablet, phablet or normal size phones?Stringency
Yes. no sim, no install. :) But it doesn't require the user to say yes to using their phone.Somatotype
@Somatotype 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.Veto
Right.. So the android:required=true would indicate "that the application cannot function". Isn't that what the OP wanted.. Only work on phone?Somatotype
I think the play store removes apps from your install options, if you don't have the required hardware.Somatotype
This works great, and I have confirmed that it still runs on an Android Emulator phone.Verify
L
11

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.

Linebreeding answered 10/8, 2014 at 16:22 Comment(9)
Arf, you are faster than me on this one ;)Knudson
large and xlarge are for 7 and 10 inch tablet right ?Relinquish
@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.Linebreeding
Nexus 5 comes in which category ?Relinquish
@Williams: According to emirweb.com/ScreenDeviceStatistics.php it should be normal.Linebreeding
Will this answer still work for modern day large phone which are 5+ inches diagonally?Drinker
@Ahmed: This answer is not tied to a specific screen size.Linebreeding
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. @LinebreedingSafko
@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.Linebreeding
K
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>
Knudson answered 10/8, 2014 at 16:24 Comment(1)
This doesn't work for all smart phones, 5X, pixes, Galaxy will be unable to download. I've tried this in production.Yellowthroat

© 2022 - 2024 — McMap. All rights reserved.