1. 程式人生 > >如何限制應用安裝,

如何限制應用安裝,

cpp term -name str keyword toa ani comm and

原文: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" />

這這樣可以了

如何限制應用安裝,