问题
Good day, I am trying to restrict screen sizes to only handsets (i.e. not tablets) in google play. After I found this article I added this to my manifest file:
<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>
But it appears that now users with 5.5++ inch phones cant install my app. Next I also found this article and picture in it:
My first question - is it possible to restrict screen size by specific inch value, or I can use only tags like small, normal, large and xlarge?
At some point I decided to increase support inch size to 7 by updating manifest like this:
<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" />
<!-- all large size screens -->
<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" />
</compatible-screens>
But users with 5.5 inch phones and even with 5.2 inch still cant install app.
So my second question - what I am doing wrong or don't understand?
I honestly read all similar questions on stackoverflow and articles in android documentation and didn't find proper answer. Thx.
回答1:
It looks like you are attempting to restrict screen sizes to only handsets, and not tablets. It is difficult to discern from your question, but either way I think I can clear up the confusion.
When you declare <compatible-screens>
in your manifest you must declare every screen configuration that you would like your app to be compatible with:
You must declare each one of these; any combination of size and density that you do not specify is considered a screen configuration with which your application is not compatible.
I suspect the 5.5+ inch phones you mention have a higher density than xhdpi
; such as xxhdpi
or xxxhdpi
. These densities are omitted from the documentation (either because the documentation is outdated or otherwise incomplete) but are still relevant; they are documented on the <compatible-screens> page.
Therefore if you want your app to be compatible with higher density devices, you must include those densities in your <compatible-screens>
element. But an easier method would be to use the <supports-screens>
element instead. As per the documentation, the <supports-screens>
element does not take density into account:
Note: Although you can also use the
<compatible-screens>
element for the reverse scenario (when your application is not compatible with smaller screens), it's easier if you instead use the<supports-screens>
as discussed in the next section, because it doesn't require you to specify each screen density your application supports.
With this you can just specify the following in your manifest:
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="false"
android:xlargeScreens="false"
android:largestWidthLimitDp="840"/>
The largestWidthLimitDp
attribute should not be necessary, but 840dp seems like a good limit for handsets based on the Material Design documentation for density breakpoints.
Otherwise, you can still use the <compatible-screens>
tag if you would like more fine-tuned control over which devices your app is compatible with:
<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" />
<screen android:screenSize="small" android:screenDensity="xxhdpi" />
<screen android:screenSize="small" android:screenDensity="xxxhdpi" />
<!-- 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" />
<screen android:screenSize="normal" android:screenDensity="xxhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
</compatible-screens>
回答2:
EDIT (2016-12-21)
After Bryan's suggest to use build tool 25.0.1, I have no more build error with his solution:
<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" />
<screen android:screenSize="small" android:screenDensity="xxhdpi" />
<screen android:screenSize="small" android:screenDensity="xxxhdpi" />
<!-- 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" />
<screen android:screenSize="normal" android:screenDensity="xxhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
BUT... with the new build some devices did not appear in the supported device list (Google Play console): Google Pixel, Nexus 5x, Google Pixel XL, Nexus 6, Nexus 6P.
That's why my new solution looks like this:
<!-- just handsets allowed-->
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" /> <!-- 120 -->
<screen android:screenSize="small" android:screenDensity="mdpi" /> <!-- 160 -->
<screen android:screenSize="small" android:screenDensity="hdpi" /> <!-- 240 -->
<screen android:screenSize="small" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="xhdpi" /> <!-- 320 -->
<screen android:screenSize="small" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="420" /> <!-- Workaround Google Pixel, Nexus 5x -->
<screen android:screenSize="small" android:screenDensity="xxhdpi" /> <!-- 480 -->
<screen android:screenSize="small" android:screenDensity="560" /> <!-- Workaround Google Pixel XL, Nexus 6, Nexus 6P -->
<screen android:screenSize="small" android:screenDensity="xxxhdpi" /> <!-- 640 -->
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" /> <!-- 120 -->
<screen android:screenSize="normal" android:screenDensity="mdpi" /> <!-- 160 -->
<screen android:screenSize="normal" android:screenDensity="hdpi" /> <!-- 240 -->
<screen android:screenSize="normal" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="xhdpi" /> <!-- 320 -->
<screen android:screenSize="normal" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="420" /> <!-- Workaround Google Pixel, Nexus 5x -->
<screen android:screenSize="normal" android:screenDensity="xxhdpi" /> <!-- 480 -->
<screen android:screenSize="normal" android:screenDensity="560" /> <!-- Workaround Google Pixel XL, Nexus 6, Nexus 6P -->
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" /> <!-- 640 -->
</compatible-screens>
OLD:
According to Bryan's answer, my manifest snippet looks like this:
<!-- just handsets allowed-->
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" /> <!-- approximately 120 dpi -->
<screen android:screenSize="small" android:screenDensity="mdpi" /> <!-- approximately 160 dpi -->
<screen android:screenSize="small" android:screenDensity="hdpi" /> <!-- approximately 240 dpi -->
<screen android:screenSize="small" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="xhdpi"/> <!-- approximately 320 dpi -->
<screen android:screenSize="small" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="420" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="480" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="560" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="640" /> <!-- Workaround -->
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" /> <!-- approximately 120 dpi -->
<screen android:screenSize="normal" android:screenDensity="mdpi" /> <!-- approximately 160 dpi -->
<screen android:screenSize="normal" android:screenDensity="hdpi" /> <!-- approximately 240 dpi -->
<screen android:screenSize="normal" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="xhdpi"/> <!-- approximately 320 dpi -->
<screen android:screenSize="normal" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="420" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="480" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="560" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="640" /> <!-- Workaround -->
</compatible-screens>
Could not use Bryan's solution because i got a compilation error: "AAPT: String types not allowed (at 'screenDensity' with value 'xxxhdpi')"
It works for (newer) devices like Google Pixel (2.6 * 160 dp = 416 dp -> 420dp -> explanation:) / Pixel XL (3.5 * 160 dp = 560 dp) or Samsung Galaxy S6 (4.0 * 160 dp = 640 dp). The dp-Values are described here: https://material.io/devices/
I think this works because the devices I mentioned above, appeared in "supported devices" list in Google Play console.
来源:https://stackoverflow.com/questions/39834843/compatible-screens-in-android