如何限制应用安装,

原文:http://blog.csdn.net/feilusia/article/details/54645998

如何限制不支持某种硬件功能的设备无法安装应用

例如限制BLE蓝牙如下设置:

1)当feature的设置为true时,只能在支持BLE的安卓设备上安装运行该APP;

  1. <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>  

2)当feature的设置为false时,则所有安卓设备上都能安装运行该APP

  1.<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/> 

但由于手机硬件上不一定支持BLE,所以需要在代码中自行判断是否支持BLE,如下:

  1. // Use this check to determine whether BLE is supported on the device. Then  
  2. // you can selectively disable BLE-related features.  
  3. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {  
  4.     Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();  
  5.     finish();  
  6. }  

实验步骤

添加蓝牙权限和feature(在AndroidManifest.xml中<!-- 声明蓝牙权限 -->  

 <uses-permission android:name="android.permission.BLUETOOTH" />   

   <!-- 允许程序发现和配对蓝牙设备 -->    

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />    

  <!-- 只能在支持BLE的Android设备上安装运行 -->    

   <uses-feature         android:name="android.hardware.bluetooth_le"       android:required="true" />  

这这样可以了

原文地址:https://www.cnblogs.com/lizhanqi/p/7422647.html