针对最大数量的受支持设备优化Android清单文件

时间:2012-12-24 05:59:11

标签: android android-manifest manifest compatibility android-compatibility

当我上传新的APK文件并且我不明白为什么时,我的问题是让我的Manifest文件与许多较新的手机兼容。我正在全新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 个答案:

答案 0 :(得分:21)

我想发布这个问题,并且一个答案,因为我发现这一开始很难搞清楚。然而,这将我支持的设备数量从499改为1968.希望这将有助于未来更多的人,因为它似乎是一个模糊的主题。

技术1:更多设备无法显示的原因是因为Google在您使用<compatible-screens>标记时过滤得更积极。在我的情况下,我没有足够的不同屏幕尺寸和密度组合,因此它过滤掉了我遗漏的所有内容(参见下面的技术2)。

如果您只使用<supports-screens />代码,那么您将可以通过更多设备找到您的应用。所以请帮自己一个忙,并删除<compatible-screens>块中的所有其他标签。

你可以使用这样的缩写形式:

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

引自original article

  

如果设备屏幕大小和,Google Play会过滤应用程序   密度与任何屏幕配置都不匹配(由a声明)   “兼容屏幕”元素中的“屏幕”元素。

     

警告:通常,您不应使用此清单元素。运用   这个元素可以大大减少你的潜在用户群   应用,通过排除屏幕尺寸和密度的所有组合   你还没有列出。你应该改用   “支持屏幕”清单元素(如上表1所示)   为您拥有的屏幕配置启用屏幕兼容模式   不考虑替代资源。

技术2 :您可以使用的另一种技术是使用<compatible-screens>标记更加特定并删除<supports-screens />标记。您可以根据应用要求以及latest device distribution numbers确定这些决策。

在下面的示例中,我不想支持小屏幕或普通,大屏或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>