安卓中的<compatible-screens>是什么意思?

11

您好,我正在尝试在Google Play中限制屏幕尺寸仅适用于手机(即不包括平板电脑)。在查阅了这篇文章之后,我将以下内容添加到我的清单文件中:

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

但是现在似乎5.5英寸及以上的手机用户无法安装我的应用程序。接下来我还发现了这篇文章,里面有这张图片:

enter image description here

我的第一个问题 - 是否可以按照具体的英寸值限制屏幕大小,或者我只能使用类似于small、normal、large和xlarge等标签?

在某个时候,我决定通过更新清单来增加支持7英寸尺寸的设备:

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

但是,即使拥有5.5英寸的手机甚至是5.2英寸的手机,用户仍然无法安装该应用程序。

所以我的第二个问题 - 我做错了什么或者我没有理解?

我诚实地阅读了stackoverflow上所有类似的问题和Android文档中的文章,并没有找到合适的答案。谢谢。

2个回答

10

编辑(2016-12-21)

在Bryan建议使用构建工具 25.0.1之后,我按照他的解决方案再也没有出现构建错误:

<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" />

但是...... 由于新版本的一些问题,一些设备未出现在支持的设备列表中(Google Play控制台):Google Pixel、Nexus 5x、Google Pixel XL、Nexus 6、Nexus 6P。

这就是为什么我的新解决方案看起来像这样:

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

NEW:

根据Bryan的回答,我的清单代码片段如下:

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

由于编译错误:“AAPT:不允许使用字符串类型(在 'screenDensity' 与值 'xxxhdpi')”,因此无法使用Bryan的解决方案。

它适用于(较新的)设备,如Google Pixel(2.6 * 160 dp = 416 dp -> 420dp ->说明:)/ Pixel XL(3.5 * 160 dp = 560 dp)或三星Galaxy S6(4.0 * 160 dp = 640 dp)。DP值在此处描述:https://material.io/devices/

我认为这是有效的,因为我提到的这些设备出现在Google Play控制台中的“支持的设备”列表中。


现在已经是2020年了,这仍然是一个问题...官方文档没有提到280、320、480和640,但如果你不包括它们,那些设备将无法像你说的那样安装它们! - Bruce
需要更新列表,因为现在有Google Pixel 3、4和5。需要添加额外的两个密度:Pixel 3a XL的400和Pixel 3/3a/4/4a/5的440。我只检查了Pixel系列和Nexus系列,所以不确定是否还有其他具有特殊密度的新设备:( - Bruce
更新我的上面的评论:似乎400和440不是compatible-screens中支持的值(如果您尝试上传,Google Play会抛出错误),根据https://dev59.com/G7bna4cB1Zd3GeqPXDRs没有解决方法,所以如果您正在指定compatible-screens,像Pixel 3、4、5用户将无法安装该应用程序:( - Bruce

6
看起来你正在尝试限制屏幕尺寸仅适用于手机,而不是平板电脑。从你的问题中很难判断,但无论如何,我认为我可以澄清混淆。
当你在清单中声明<compatible-screens>时,你必须声明每一个你想让你的应用程序兼容的屏幕配置:
"你必须声明每一种组合;你没有指定的大小和密度,被视为与你的应用程序不兼容的屏幕配置。"
我怀疑你提到的5.5英寸以上的手机比xhdpi具有更高的密度;例如xxhdpixxxhdpi。这些密度在文档中被省略了(可能是因为文档已过时或不完整),但仍然是相关的;它们在<compatible-screens>页面上有记录。
因此,如果您希望您的应用程序与高密度设备兼容,必须在<compatible-screens>元素中包含这些密度。但更简单的方法是使用<supports-screens>元素。根据文档,<supports-screens>元素不考虑密度:

注意:虽然您也可以使用<compatible-screens>元素进行相反的情况(当您的应用程序不兼容较小的屏幕时),但如果您改为使用下一节中讨论的<supports-screens>,会更容易,因为它不需要指定您的应用程序支持的每个屏幕密度。

有了这个,您只需在清单中指定以下内容:

<supports-screens android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="false"
                  android:xlargeScreens="false"
                  android:largestWidthLimitDp="840"/>

"

largestWidthLimitDp 属性不是必需的,但根据 Material Design 文档中 density breakpoints 的建议,840dp 似乎是智能手机的一个好限制。

否则,如果您希望更精细地控制应用程序与哪些设备兼容,仍然可以使用 <compatible-screens> 标签:

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

是的,抱歉我的英语不好,但你理解得很正确。谢谢! - Panich Maxim
2
@Bryan:你提供的解决方案 <screen android:screenSize="small" android:screenDensity="xxhdpi" /> <screen android:screenSize="small" android:screenDensity="xxxhdpi" /> 无法编译:“AAPT:不允许字符串类型(在'value'为'xxxhdpi'的'screenDensity'处)”。我知道这个解决方案是由Google自己提供的(https://developer.android.com/guide/topics/manifest/compatible-screens-element.html)- 真是个笑话... - A.D.
可能是构建工具版本的问题,我正在使用最新版本 25.0.1。您仍然可以使用每个密度的数值(即 xhdpi => 320xxhdpi => 480 等),但您应该考虑升级到最新的构建版本。 - Bryan
@Bryan,谢谢,我已经更新到25.0.1版本了,现在可以正常工作了。请查看我的编辑后的答案。 - A.D.
1
根据谷歌的说法,您不能使用supports-screens来排除较大的屏幕:“注意:如果您使用<supports-screens>元素进行反向场景(当您的应用程序与较大的屏幕不兼容时),并将较大的屏幕大小属性设置为“false”,那么像Google Play这样的外部服务就不会应用过滤”。请参见:https://developer.android.com/guide/practices/screens-distribution.html - David
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接