android4.0 及以上 版本里 ,如果在settings下看不到wifi和bluetooth两个菜单选项,这是因为在setting里,对系统是否有特定的模块加上了判断,如果没有就不显示。android4.0的模块判断函数:getPackageManager().hasSystemFeature(String string).通过该函数判断系统是否有特定的模块功能。
例如判断是否有 wifi 和 蓝牙模块的具体代码:
getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI);
getPackageManager().hasSystemFe(PackageManager.FEATURE_BLUETOOTH);
PackageManager这些字符串 存在system/etc/permissions/xxxx.xml文件里,它们一般从/framework/base/data/etc/xxx.xml复制过来。
PackageManager.FEATURE_BLUETOOTH = "android.hardware.wifi"
PackageManager.FEATURE_BLUETOOTH = "android.hardware.bluetooth"
解决wifi和蓝牙不显示方法:
一、直接把包含对应 feature 的xml文件复制到system/etc/permissions/目录下,相当于加上系统所具有的具体模块的功能配置文件;
二、直接把Settings.java(packages/app/Settings/com.android.settings)里onBuildHeaders里的updateHeaderList(headers)注释掉,相当于去掉判断条件。
++++++++++++++++++++++++++++++++++++++++++
相关方法如下:
FeatureInfo[] PackageManager.getSystemAvailableFeatures()
boolean PackageManager.hasSystemFeature(String feature)
范例:
PackageManager pm = context.getPackageManager();
FeatureInfo[] features = pm.getSystemAvailableFeatures(); //得到所有支援的硬體種類
for (FeatureInfo feature : features) Log.v(TAG, feature.name);
boolean hasFlashlight = pm.hsaSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); //是否支援閃光燈
boolean hasCamera = pm.hsaSystemFeature(PackageManager.FEATURE_CAMERA); //是否支援相機
boolean hasBt = pm.hsaSystemFeature(PackageManager.FEATURE_BLUETOOTH); //是否支援藍牙
hasSystemFeature 這個接口參考信息是
/system/etc/permissions/android.hardware*.xml 文件中定義的feature的信息
/frameworks/base/data/etc/android.hardware.camera.flash-autofocus.xml
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<feature name="android.hardware.camera" />
<feature name="android.hardware.camera.autofocus" />
<feature name="android.hardware.camera.flash" />
</permissions>