赞
踩
一、android frameworks里面经常会看到getPackageManager().hasSystemFeature,比如frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\policy\FlashlightControllerImpl.java里面检查硬件是否闪光灯。
二、getPackageManager().hasSystemFeature是用来检查android设备是否支持某些功能
我们在开发APP的时候,应用程序可能需要设备支持某些功能才能保证应用程序的运行。例如需要支持电话、陀螺仪等等。我们可以使用PackageManager对象的hasSystemFeature方法来检查当前设备是否支持某些功能。
三、分析一下AvailableFeature从哪里获取的
1、frameworks\base\core\java\android\app\ApplicationPackageManager.java
2、frameworks\base\services\core\java\com\android\server\pm\PackageManagerService.java
3、frameworks\base\core\java\com\android\server\SystemConfig.java里去获取支持的硬件设备,红框里面读取/vendor/etc/permissions/下面的xml文件。
4、/vendor/etc/permissions/下面的文件,支持camera的xml文件的方式如下。
- <?xml version="1.0" encoding="utf-8"?>
- <!-- Copyright (C) 2009 The Android Open Source Project
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
- <!-- This is the standard feature indicating that the device includes WiFi. -->
- <permissions>
- <feature name="android.hardware.wifi" />
- </permissions>
四、这里我自定义一个giadahdmicec硬件功能。
1、app里面检查是否支持giadahdmicec功能
2、把android.hardware.giada.xml文件adb push到/vendor/etc/permissions/目录下面
- <?xml version="1.0" encoding="utf-8"?>
- <!-- Copyright (C) 2009 The Android Open Source Project
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
- <!-- This is the standard set of features for a camera with a flash. Note
- that this currently requires having auto-focus as well. -->
- <permissions>
- <feature name="android.hardware.giadahdmicec" />
- </permissions>
3、运行app,说明该设备support cec功能。
4、在AndroidManifest.xml文件中使用<uses-feature/>标签,来告诉Android Market此应用程序必须满足标签中指定功能才可以使用,这样Android Market会根据应用程序的指定的要求,来过滤所有不支持的设备。
五、参考文章
检查android设备是否支持某些功能 - 仰望 星空 - 博客园
PackageManager hasSystemFeature_a281629221的博客-CSDN博客_android hassystemfeature
android-getPackageManager().hasSystemFeature(String string)的应用_zJianFlys的博客-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。