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. android studio Could not find com.android.support.constraint
  2. android ndk编译x264开源(用于android的ffmpeg中进行软编码)
  3. GitHub 优秀的 Android(安卓)开源项目
  4. Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
  5. Android获取设备唯一标识完美解决方案
  6. android WebView 图片缩放功能小结
  7. android加密解密完美教程
  8. 【Android(安卓)应用开发】GitHub 优秀的 Android(安卓)开源项目
  9. android支持多行的radiogroup

随机推荐

  1. LinearLayout和RelativeLayout的属性区别
  2. Android(安卓)透明Dialog
  3. android 自定义组件圆形边框
  4. APIDEMO ACTIVITY 屏幕在出现软键盘情况
  5. Android(安卓)图片拖动和缩放
  6. Android控件常用属性
  7. Android(安卓)安装环境搭建
  8. android布局属性详解
  9. 2011.06.22——— android framelayout布
  10. 安卓调用键盘回车键做保存或调用搜索键执