Android中的<compatible-screens>

时间:2016-10-03 15:11:54

标签: android google-play screen-size

美好的一天,我试图将屏幕大小限制为仅限于谷歌播放中的手机(即不是平板电脑)。在我找到这个article后,我将其添加到我的清单文件中:

<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 ++英寸手机的用户无法安装我的应用程序。接下来我还发现了article并在其中找到了图片:

enter image description here

我的第一个问题 - 是否可以将屏幕尺寸限制为特定的英寸值,或者我只能使用小型,普通型,大型和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文档中的文章的所有类似问题,并没有找到正确的答案。 THX。

2 个答案:

答案 0 :(得分: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" />

... BUT 使用新版本,某些设备未出现在支持的设备列表(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>

<强> OLD:

根据布莱恩的回答,我的清晰片段看起来像这样:

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

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

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

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

答案 1 :(得分: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"/>

largestWidthLimitDp属性不是必需的,但基于density breakpoints的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>