Android中的<compatible-screens>

Pan*_*xim 6 android screen-size 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>
Run Code Online (Sandbox Code Playgroud)

但现在看来,使用5.5 ++英寸手机的用户无法安装我的应用程序.接下来我也发现了这篇文章和图片:

在此输入图像描述

我的第一个问题 - 是否可以将屏幕尺寸限制为特定的英寸值,或者我只能使用小型,普通型,大型和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>
Run Code Online (Sandbox Code Playgroud)

但使用5.5英寸手机甚至5.2英寸的用户仍然无法安装应用程序.

所以我的第二个问题 - 我做错了什么或不明白?

我老老实实地读了关于stackoverflow和android文档中的文章的所有类似问题,并没有找到正确的答案.谢谢.

A.D*_*.D. 8

编辑(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" />
Run Code Online (Sandbox Code Playgroud)

但是......在新版本中,某些设备未出现在支持的设备列表(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>
Run Code Online (Sandbox Code Playgroud)

旧:

根据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>
Run Code Online (Sandbox Code Playgroud)

无法使用Bryan的解决方案因为我收到了编译错误:"AAPT:字符串类型不允许(在'screenDensity'中,值为'xxxhdpi')"

它适用于(较新的)设备,如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-values:https://material.io/devices/

我认为这是有效的,因为我上面提到的设备出现在Google Play控制台的"支持的设备"列表中.


Bry*_*yan 5

看起来您试图将屏幕尺寸仅限于手机,而不是平板电脑.很难从你的问题中辨别出来,但无论哪种方式,我认为我都可以解决这个问题.

当您<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"/>
Run Code Online (Sandbox Code Playgroud)

largestWidthLimitDp属性不是必需的,但对于基于密度断点的Material Design文档的手机来说,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>
Run Code Online (Sandbox Code Playgroud)

  • @Bryan:你提供的解决方案<screen android:screenSize ="small"android:screenDensity ="xxhdpi"/> <screen android:screenSize ="small"android:screenDensity ="xxxhdpi"/>将无法编译:"AAPT:不允许使用字符串类型('screenDensity',值为'xxxhdpi')".我知道此解决方案由Google自己提供(https://developer.android.com/guide/topics/manifest/compatible-screens-element.html ) - 真是笑话... (2认同)