【问题标题】:How to restrict app to Android phones only如何将应用程序仅限于 Android 手机
【发布时间】:2014-08-10 16:14:52
【问题描述】:

您好,我仅将用户定位到Android 电话。我想限制应用程序安装在Android 手机上,而不是平板电脑和平板电脑上。

我需要在 AndroidManifest.xml 中应用哪些配置,以便 Google Play 应用不会在表格和平板手机中显示该应用。

提前致谢。

【问题讨论】:

标签: android android-screen-support


【解决方案1】:

引用the documentation:

由于系统通常会缩放应用程序以很好地适应更大的屏幕,因此您不需要从更大的屏幕中过滤您的应用程序。只要您关注Best Practices for Screen Independence,您的应用程序就应该可以在平板电脑等更大的屏幕上正常运行。但是,您可能会发现您的应用程序无法很好地扩展,或者您可能决定针对不同的屏幕配置发布两个版本的应用程序。在这种情况下,您可以使用<compatible-screens> 元素根据屏幕尺寸和密度的组合来管理应用程序的分布。 Google Play 等外部服务使用此信息对您的应用程序进行过滤,以便只有具有您声明兼容的屏幕配置的设备才能下载您的应用程序。

请记住,<compatible-screens> 要求您将您支持的每个屏幕尺寸和密度列入白名单(我们每年左右都会获得一个新的密度),并且您仅限于经典屏幕大小的桶(smallnormallargexlarge)。文档的样本缺少一些密度:

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

如果愿意支持tvdpixxhdpixxxhdpi 设备,您将需要添加其他元素。

引用the documentation for &lt;compatible-screens&gt;:

警告:通常情况下,您不应使用此清单元素。使用此元素可以显着减少应用程序的潜在用户群,因为如果用户的设备具有您未列出的屏幕配置,则不允许他们安装您的应用程序。当应用程序绝对不能使用特定的屏幕配置时,您应该仅将其用作最后的手段。您应该遵循支持多个屏幕的指南,而不是使用此元素,使用针对不同屏幕尺寸和密度的替代布局和位图为多个屏幕提供可扩展的支持。

请记住,诸如“平板手机”之类的营销术语定义不明确,因此您的应用可能最终会在您认为是平板手机或其他人认为是平板手机的某些设备上发布。

【讨论】:

  • Arf,这个你比我快;)
  • large 和 xlarge 适用于 7 英寸和 10 英寸平板电脑,对吗?
  • @Williams:official docsdp 中为这些存储桶指定最小大小。粗略地说,large 开始于对角线 5 英寸左右,而xlarge 开始于 10 英寸对角线。
  • Nexus 5 属于哪个类别?
  • @Williams:根据emirweb.com/ScreenDeviceStatistics.php 应该是normal
【解决方案2】:

另一种方法是测试 android.hardware.telephony 功能

<uses-feature android:name="android.hardware.telephony" android:required="true" />

这会将应用程序限制在手机上。当然,平板手机会包含在其中,但(恕我直言)这将是比不断变化的屏幕分辨率方法更好的解决方案。

【讨论】:

  • 是否只允许在支持 sim 的设备上安装应用程序,无论是平板电脑、平板手机还是普通尺寸的手机?
  • 是的。没有sim,没有安装。 :) 但它不需要用户同意使用他们的手机。
  • @baash05 来自official docs 它说:----当您为某个功能声明 android:required="true" 时,您指定该应用程序无法运行,或者不是旨在功能,当设备上不存在指定的功能时。当您为某个功能声明 android:required="false" 时,这意味着如果设备上存在该功能,应用程序更喜欢使用该功能,但如果需要,它被设计为在没有指定功能的情况下运行。
  • Right.. 所以 android:required=true 表示“应用程序无法运行”。这难道不是 OP 想要的……只能在手机上工作?
  • 如果您没有所需的硬件,我认为 Play 商店会从您的安装选项中删除应用程序。
【解决方案3】:

由于 Nexus 5X、Nexus 6P 和三星 Galaxy S6 等新设备的高密度,我们不得不对清单进行如下调整:

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

【讨论】:

  • 你在 prod 中测试过这个吗?直到上个月,当我们看到不支持 Pixel 和新的三星 S8 等设备时,我们一直在使用上面的“旧”答案? 快速删除了它,但现在我们支持平板电脑,这并不是我们真正想要的.这感觉很乱!
  • 以上配置在 Play 商店下载中是否有效?
  • @PärNilsAmsen 您从@Displayname 那里得到答案了吗?我也在问同样的问题,尤其是在 2018 年,Pixel 3 和 Pixel 3 Excel 等更大密度的手机发布了。
  • 抱歉回复晚了,我目前没有在生产中使用上述过滤器,所以很遗憾,我不知道这对于屏幕更大的新设备会有什么影响
  • @CompaqLE2202x 回复较晚,但最后我只是删除了整个compatible-screens 块,我建议不要将其用于排除平板电脑。说真的,不要这样做。我们及时抓住了过滤器,它过滤了我们想要的很多设备。自从它被删除以来,没有任何问题。相反,我们使用android.hardware.telephony 解决方案来过滤掉 99% 的平板电脑和其他非智能手机设备,并且运行良好。
【解决方案4】:

这真的取决于您对手机/平板手机的看法。

有一个official guide 会比我解释得更好,但本质上,您可以执行以下操作以将您的应用程序仅限于手机设备。

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>

【讨论】:

  • 这不适用于所有智能手机,5X,像素,Galaxy 将无法下载。我已经在生产中尝试过了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-30
  • 1970-01-01
  • 1970-01-01
  • 2011-02-18
  • 1970-01-01
相关资源
最近更新 更多