为最大化支持设备,优化Android清单文件

13

我上传新的APK文件时,我的清单文件无法与许多较新的手机兼容,但我不明白为什么。我正在全新的HTC Evo V上测试它,但由于某种原因,该设备不会显示在兼容性列表中。

我使用API 17进行编译,并支持最低API 10,这应该包括大多数手机。

我尝试过:

  • 删除所有权限;没有变化
  • 尝试使WIFI不是必需的;没有变化
  • 删除installLocation以查看是否有所不同;没有变化
  • 甚至尝试添加小屏幕支持以查看是否会出现;没有变化

我所阅读的:

我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.somecompany.appname"
      android:versionCode="10"
      android:versionName="1.0"
      android:installLocation="preferExternal">

    <!-- For expansion pack downloads -->
    <!-- Required to access Android Market Licensing -->
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
    <!-- Required to download files from Android Market -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Required to keep CPU alive while downloading files (NOT to keep screen awake) -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <!-- Required to poll the state of the network connection and respond to changes -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Required to check whether Wi-Fi is enabled -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <!-- Required to read and write the expansion files on shared storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17"/>
    <supports-screens android:normalScreens="true"/>
    <supports-screens android:largeScreens="true"/>
    <supports-screens android:xlargeScreens="true"/>

    <compatible-screens>
        <screen android:screenSize="normal" android:screenDensity="mdpi" />
        <screen android:screenSize="large" android:screenDensity="hdpi" />
        <screen android:screenSize="xlarge" android:screenDensity="xhdpi" />
    </compatible-screens>                      
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="false">
        <activity android:name="somecompany.appname.SplashScreen"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="somecompany.appname.SoundAndCallActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar"/>
        <activity android:name="somecompany.appname.MainScreenActivity"   android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar"/>
        <activity android:name="somecompany.appname.SettingsActivity"   android:screenOrientation="portrait" android:theme="@style/Theme.Transparent"/>
    </application>
</manifest>
1个回答

23

我想发布这个问题和答案,因为一开始我也觉得很困惑。但是这改变了我的支持设备数量,从499个增加到了1968个。希望这对未来更多的人有所帮助,因为这似乎是一个晦涩的话题。

技巧1: 更多设备未显示的原因是因为当你使用<compatible-screens>标签时,Google会更加严格地过滤。在我的情况下,我没有足够的不同屏幕尺寸和密度组合,因此它过滤掉了我留下的所有屏幕(请参见下面的技巧2)。

如果你只使用<supports-screens />标签,那么你将使你的应用程序被更多设备找到。所以,请自己方便起见,删除<compatible-screens>块中的所有其他标签。

你可以使用像这样的简写:

<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"></supports-screens>

引用自原始文章

如果设备屏幕大小和密度与“compatible-screens”元素中声明的任何屏幕配置不匹配,则Google Play将过滤应用程序。

注意:通常情况下,您不应使用此清单元素。使用此元素可能会显著减少应用程序的潜在用户群,因为您未列出的所有屏幕大小和密度组合都将被排除在外。相反,您应该使用“supports-screens”清单元素(在表1中描述)启用屏幕兼容模式,以适应您未考虑替代资源的屏幕配置。

技巧2:另一个技巧是更具体地使用您的<compatible-screens>标记,并摆脱<supports-screens />标记。您可以根据您的应用程序要求和最新的设备分布数字做出这些决策。

在下面的示例中,我不想支持小屏幕或正常、大屏幕或xlarge屏幕的ldpi密度,因此我将它们留了下来。

<compatible-screens>
    <!-- all normal size screens -->
    <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="mdpi" />
    <screen android:screenSize="large" android:screenDensity="hdpi" />
    <screen android:screenSize="large" android:screenDensity="xhdpi" />
    <!-- all xlarge size screens -->
    <screen android:screenSize="xlarge" android:screenDensity="mdpi" />
    <screen android:screenSize="xlarge" android:screenDensity="hdpi" />
    <screen android:screenSize="xlarge" android:screenDensity="xhdpi" />
</compatible-screens>

1
@Arash 我现在正在转向Android领域,希望这能帮助其他一些和我一样的人。 - iwasrobbed
“这使得我支持的设备数量从499增加到了1968” - @iWasRobbed 你是怎么得出这些数字的? - skataben
当您在Google Play开发者控制台上上传新的APK时,它们会显示出来。 - iwasrobbed
等一下,我应该同时拥有支持的屏幕和兼容的屏幕吗?还是只需要一个?为什么?谢谢老兄。 - user5562706

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