关闭

AndroidManifest.xml 详解 (五) 之uses-feature—— 译自《Beginning Android Games》

标签: androidapplication游戏integerfilterattributes
5438人阅读 评论(0) 收藏 举报
分类:

    The <uses-feature> Element

    如果你是一个Android用户,而且你有一个老旧的安装有android 1.5 的android设备,你可能会注意到一些高版本的应用没有在手机上的Android Market 中显示。这必定是应用使用了<uses-feature>的结果。

 

    Android Market会根据uses-feature过滤所有你设备不支持的应用。通过使用<uses-feature>元素,一个应用可以指定它所支持的硬件型号,举个例子,有些设备不支持多点触控或者OpenGL ES 2.0,那么过滤器就会过滤需要这些硬件支持(多点触控或者OpenGL ES 2.0)的应用,用户就不会在android market上看到这些应用。

 

    一个<uses-feature>元素包含以下属性:

    <uses-feature android:name="string" android:required=["true" | "false"]  android:glEsVersion="integer" />

      

    name属性指定了应用的特征,required属性告诉过滤器我们是否在任何情况下必须要需要这个设备的支持,或者仅仅只是“nice to have”。

   

    最后一个属性是可选择的,只是用在需要指定一个OpenGL ES版本的时候。

   

    接下来的几个硬件特征对于游戏开发是非常有用的。

   

    android.hardware.touchscreen.multitouch:它要求设备有一个多点触控的屏幕以支持基本的多点触控交互,就如收缩(放大)图像比例。这些类型的屏幕跟踪多个手指的能力都有所不同,所以你必须确保这个屏幕的性能是能够支持的游戏进行。

   

    android.hardware.touchscreen.multitouch.distinct: 这是一个多点触控的兄弟属性,它要求提设备供完整的多点触控功能。

 

    我们将会在接下来的章节片段中看到多点触控。现在只要记住在当你的游戏需要一个支持多点触控的屏幕的时候,我们可以使用 <uses-feature>元素来剔除所有不支持多点触控的设备,就像下面这样:

   

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

 

    另外一个在游戏开发中非常有用的是去指定需要的OpenGL ES版本。在本书中,我们只关心OpenGL ES1.0和OpenGL ES1.1就可以了。由于这2者基本上没有什么不同,所以我们也不用去指定<uses-feature>了。然而,有些设备支持更强大的OpenGL ES2.0

如果你的游戏需要更强大的图形处理能力,我们可以指定OpenGL ES 2.0,然后我们的游戏只会被支持OpenGL ES 2.0的设备所看见。注意,在本书中不会使用OPenGL ES 2.0, 我们只是过滤那些不能提供足够图形处理能力的设备。下面显示了我们怎么去实现它。

   

    <uses-feature android:glEsVersion="0x00020000" required="true"/>

 

    它将使我们的游戏只被支持OPenGL ES 2.0 和 假装有相当的图形处理能力的设备所看到。

   

    NOTE: 有些设备所反映的性能特征是不正确的,所以开发你的应用的时候尽量去支持各种不同的设备。要谨慎使用<uses-feature>。

   

    现在就以硬件而言,你的应用已经直接地减少了许多安装量,这将直接影响到你应用的销量。所以当你定义<uses-feature>之前请慎重考虑。举个例子,如果你的游戏需要有多点触控的支持,但是我们也可以思考另外一种方法,是游戏能够在支持单点触控的设备上运行良好,我们就可以写2个路径的代码,分别在两种设备上运行。

 

下一个是<uses-sdk>

 

另附上原文

 

The <uses-feature> Element


If you are an Android user yourself and possess an older device with an old Android
version like 1.5, you will have noticed that some awesome applications won’t show up
the Android Market application on the device. One reason for this can be the use of th
<uses-feature> element in the manifest file of the application.


The Android Market application will filter all available applications by your hardware
profile. With the <uses-feature> element, an application can specify which hardware
features it needs—for example, multitouch or support for OpenGL ES 2.0. Any device
that does not have the specified features will trigger that filter so that the end user isn’
shown the application in the first place.


A <uses-feature> element has the following attributes:


<uses-feature android:name="string" android:required=["true" | "false"] android:glEsVersion="integer" />


The name attribute specifies the feature itself. The required attribute tells the filter
whether we really need the feature under all circumstances or if it’s just nice to have.

 

The last attribute is optional and only used in conjunction with requiring a specific
OpenGL ES version.


For game developers, the following features are most relevant:
android.hardware.touchscreen.multitouch: This requests that the device have a
multitouch screen capable of basic multitouch interactions, such as pinch zooming
and the like. These types of screens have problems with tracking multiple fingers
independently, so you have to evaluate if those capabilities are sufficient for your
game. 


android.hardware.touchscreen.multitouch.distinct: This is the big brother of the
last feature. This requests full multitouch capabilities suitable to implement things
like onscreen virtual dual sticks for controls.


We’ll look into multitouch in a later section of this chapter. For now it suffices to
remember that when our game requires a multitouch screen, we can weed out all
devices that don’t support that feature by specifying a <uses-feature> element with one
of the preceding feature names, like so:


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


Another useful thing for game developers is to specify which OpenGL ES version is
needed. Now, in this book we’ll be concerned with OpenGL ES 1.0 and 1.1. For these,
we usually don’t specify a <uses-feature> element, as they aren’t all that different from
each other. However, any device that implements OpenGL ES 2.0 can be assumed to be
a graphics powerhouse. If our game is visually complex and needs a lot of processing
power, we can require OpenGL ES 2.0 so that the game only shows up for devices that
are able to render our awesome visuals at an acceptable frame rate. Note that we don’t
use OpenGL ES 2.0, but just filter by hardware type so that our OpenGL ES 1.x code
gets enough processing power. Here’s how we can do this:


<uses-feature android:glEsVersion="0x00020000" required="true"/>


This will make our game only show up on devices that support OpenGL ES 2.0 and are
thus assumed to have a fairly powerful graphics processor. 


NOTE: This feature is reported incorrectly by some devices out there, making your application
invisible to otherwise perfectly fine devices. Use it with caution.


Now, every specific requirement you have in terms of hardware potentially decreases
the amount of devices your game can be installed on, directly affecting your sales. Think
twice before you specify any of the above. For example, if the standard mode of our
game requires multitouch but we can also think of a way to make it work on single-touch
devices, we should strive for having two code paths, one for each hardware profile, to
be able to deploy to a bigger market.

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:69572次
    • 积分:1057
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:9篇
    • 译文:9篇
    • 评论:20条
    文章分类