android判断一个功能是否可用
2015-07-14 10:03
281 查看
[code]Device features In order for you to manage your app’s availability based on device features, Android defines feature IDs for any hardware or software feature that may not be available on all devices. For instance, the feature ID for the compass sensor is FEATURE_SENSOR_COMPASS and the feature ID for app widgets is FEATURE_APP_WIDGETS. If necessary, you can prevent users from installing your app when their devices don't provide a given feature by declaring it with a <uses-feature> element in your app's manifest file. For example, if your app does not make sense on a device that lacks a compass sensor, you can declare the compass sensor as required with the following manifest tag: <manifest ... > <uses-feature android:name="android.hardware.sensor.compass" android:required="true" /> ... </manifest> Google Play Store compares the features your app requires to the features available on each user's device to determine whether your app is compatible with each device. If the device does not provide all the features your app requires, the user cannot install your app. However, if your app's primary functionality does not require a device feature, you should set the required attribute to "false" and check for the device feature at runtime. If the app feature is not available on the current device, gracefully degrade the corresponding app feature. For example, you can query whether a feature is available by calling hasSystemFeature() like this: PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) { // This device does not have a compass, turn off the compass feature disableCompassFeature(); }
上面的官方api说的就是怎么去注册一个功能的使用权限,以及手机是否有这个功能是否可以使用这个功能
http://developer.android.com/guide/practices/compatibility.html#defined
相关文章推荐
- android 滑动导航效果FragmentTabViewPager
- Android Studio使用技巧系列教程(四)
- Android版xx助手之天天酷跑外挂详细分析
- Android-无法隐藏标题栏
- ANDROID AIDL(安桌接口定义语言)
- Android中的线程与进程之间的关系简单解释
- ViewPager禁止滑动以及它与内层滑动控件水平方向上事件冲突的解决方法
- 自定义类似RadioButton的单选、多选的ListView
- android:自定义组合控件Weight(高仿猫眼底部菜单栏)
- android的DialogFragment设置全屏之后,里面的View不能充满整个屏幕
- Android R文件报错问题
- Android 国内集成使用谷歌地图
- Android Studio for windows环境搭建
- Android Studio 问题 - Clear Read-Only Status
- 完美解决Android SDK Manager无法更新
- Android 开发 之 Fragment 详解
- 解决Android Studio中某一个Module不能启动的问题
- Android 带清除功能的输入框控件ClearEditText,仿IOS的输入框
- Android 访问权限设置
- Android自定义圆形图片和文本