2022-04-21 Android 使用getPackageManager().hasSystemFeature方法来检查当前设备硬件是否支持某些功能

2023-05-16

一、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博客

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

2022-04-21 Android 使用getPackageManager().hasSystemFeature方法来检查当前设备硬件是否支持某些功能 的相关文章

随机推荐

  • vue项目报错Expected indentation of 2 spaces but found 4

    报错原因 严格的检查缩进问题 xff0c 不是报错 xff0c 我们可以关闭这个检查规则 解决方案 找到以下的文件 xff0c 添加 34 indent 34 34 off 34 2 然后在终端输入npm run dev 如果觉得能帮助到你
  • Shared-memory Based Ring Buffer

    This post explains how to implement a ring buffer that can be shared between multiple processes For the simplicity and e
  • Ubuntu系统无法进入图形化界面【笔记】

    服务器位置 显示器变更后 xff0c Ubuntu系统无法进入图形化界面 现场情况 xff1a alt 43 ctrl 43 F1 无反应 xff0c alt 43 ctrl 43 F1 F6 有反应 1 alt 43 ctrl 43 F2
  • 生产者与消费者设计模式(一对一,一对多,多对多)——Java实现

    第一次发文 xff0c 如有错误 xff0c 欢迎指正 1 首先 xff0c 我们创建一个消费对象 public class StaticVariate public static List Pc 61 new ArrayList 2 创建
  • Linux 下 FTP 连接使用方式及常用配置

    Linux 下 FTP 连接使用方式及常用配置 FTP 协议介绍传输方式支持模式FTP 客户端注意事项FTP 协议连接步骤FTP 常用命令 Linux下 FTP 常用命令Linux 下连接 FTP 服务器Linux下 FTP 目录操作Lin
  • IDEA开发工具使用 git 创建项目、拉取分支、合并分支

    工作中多人使用版本控制软件协作开发 xff0c 常见的应用场景归纳如下 xff1a 假设小组中有两个人 xff0c 组长小张 xff0c 组员小袁 场景一 xff1a 小张创建项目并提交到远程Git仓库 场景二 xff1a 小袁从远程Git
  • CSS应用

    任务4 1 使用CSS样式美化购物列表页面中的菜单导航栏 任务4 2 使用CSS样式美化购物列表页面中的商品展示区 任务5 1 使用CSS样式实现购物列表页面的整体布局 任务5 2 使用CSS样式实现购物列表页面的左侧导航栏部分
  • XPath的使用(基本的使用方式,心得,持续添加)

    1 心得 xff1a 解析网页时 xff0c 使用过HtmlAgilityPack这个类库 xff0c 里面用到了XPath来查找结点 在使用过程中 xff0c 因为html文本的标签十分多 xff0c 大部分元素是没有id属性的 xff0
  • 姿态解算原理(一)——旋转矩阵

    像我们常见的MPU6050 MPU9250等等都是一种捷联式的惯性元件 xff0c 还是一种低成本的 xff0c 还有一种是平台式的惯性导航 xff0c 不过我们能够用得起的就是低成本的MEMS惯性元件 xff0c 本文的内容是姿态解算的原
  • linux 设置自动关机和重启命令shutdown

    1 shutdown使用命令 xff1a Shutdown 选项 时间 参数解释 xff1a k 不真关机向所有用户提示警告信息 r 关机后立即重新启动 h 关机 f 快速关机重启动时跳过fsck n 快速关机不经过init 程序 c 取消
  • manifest.json

    34 name 34 34 Shopro开源商城 34 34 appid 34 34 UNI 34 34 description 34 34 Shopro开源商城 34 34 versionName 34 34 1 3 2 34 34 ve
  • 普通人对AI的看法

    就发展前景来看 xff0c 人工智能无疑将是现阶段与今后很长时间内的全球性热点 这是一个可以预见性的历史潮流 xff0c 无可阻挡 xff0c 一旦它出现一定会对现代互联网的结构会产 生颠覆性的改变 它将重新定义现代互联网的理念 xff0c
  • expect_out(buffer)中包含send的数据

    expect out buffer 中包含send的数据 我一直以为在Expect中一旦执行send之后 xff0c expect out buffer 就会被清空 xff0c 直到有新的数据被填入 xff0c 而恰恰就是这些数据被用在ex
  • Python在Linux环境中获取文件名并读取文件内容格式化输出

    Python在Linux环境中获取文件名并读取文件内容格式化输出 代码示例 xff1a span class token comment usr bin python3 span span class token comment codin
  • FindBugs 汇总(持续修改)

    FindBugs 所有的问题 xff0c 个人遇到的会进行简单的记录 BC Equals method should not assume anything about the type of its argument BC EQUALS
  • 使用原版镜像安装windows时install.wim文件过大的解决方案

    现在安装win10系统一般使用微软的原版镜像 xff0c 去msdn i tell you 这个网站下载合适版本的ISO镜像解压到u盘中即可引导安装 如果使用uefi引导的话 xff0c u盘的文件系统需要为fat32格式才能正确引导 xf
  • 对比学习:MoCo代码详解

    MoCo算法代码详解 本文代码来源 xff1a 1 导入包2 参数设置3 数据预处理4 模型4 1moment update key encoder4 2进队出队4 3shuffle4 4损失计算 5 训练6 测试6 1 Knn monit
  • 【Linux】centos sudo: java: command not found解决方案

    一 解决方案 1 登入能执行命令的用户 xff0c 修改用户系统变量 比如centos登入 vim bashrc 2 赋予sudo环境变量 xff0c 设置别名 alias sudo 61 34 sudo env PATH 61 PATH
  • linux 中.sh文件如何打开运行

    1 sh是linux中运行shell的命令 xff0c 是shell的解释器 xff0c shell脚本是linux中壳层与命令行界面 xff0c 用户可以在shell脚本输入命令来执行各种各样的任务 要运行shell脚本 xff0c 首选
  • 2022-04-21 Android 使用getPackageManager().hasSystemFeature方法来检查当前设备硬件是否支持某些功能

    一 android frameworks里面经常会看到getPackageManager hasSystemFeature xff0c 比如frameworks base packages SystemUI src com android