zoukankan      html  css  js  c++  java
  • 如何限制应用安装,

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

    这这样可以了

  • 相关阅读:
    为什么要用where 1=1?
    idea中.ignore忽略提交文件到Git的使用
    IDEA开发工具使用 git 创建项目、拉取分支、合并分支
    Linux常用命令及Linux系统根目录下各个目录的作用
    Xshell和Xftp的安装与使用教程
    Moco使用简单指导
    这样写会有什么问题呢?
    grunt学习笔记
    基于nginx的WebSocket反向代理
    maven依赖查找方法
  • 原文地址:https://www.cnblogs.com/lizhanqi/p/7422647.html
Copyright © 2011-2022 走看看