• 2017-03-1<Bluetooth基本操作>


    public class Bluetoothcontroller {
    private BluetoothAdapter ba;

    public Bluetoothcontroller() {
    this.ba = BluetoothAdapter.getDefaultAdapter();
    }
    /*
    * 判断设备是否支持蓝牙
    * true支持
    * false不支持
    * */
    public boolean isBluetooth(){
    if(ba!=null){
    return true;
    }else {
    return false;
    }
    }
    /*
    * 判断蓝牙状态
    * 条件一:ba!=null 蓝牙设备不为空
    * 条件二:ba.isEnabled() 判断蓝牙是否开启
    * 满足条件一执行条件二 不满足条件一 执行false
    * 如果不判断蓝牙设备是否存在 直接判断蓝牙状态 在没有蓝牙设备的情况下 将会空指针
    * */
    public boolean BluetoothStatu(){
    return ba!=null ? ba.isEnabled():false;
    }
    /*
    * 打开蓝牙
    * */
    public void OpenBluetooth(Activity activity,int requestcode){
    //获取蓝牙;唤起界面
    Intent i=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    activity.startActivityForResult(i,requestcode);
    }
    /*
    * 关闭蓝牙
    * */
    public void OffBluetooth(){
    ba.disable();
    }
    }
  • 相关阅读:
    自动生成 Makefile 的全过程详解
    cpio实例讲解
    RPM命令手册
    SSHFS
    shell脚本命令行参数传递问题
    批量改名总结
    例解 autoconf 和 automake 生成 Makefile 文件
    Shell中的shift命令
    cpio命令详解
    Git笔记基础
  • 原文地址:https://www.cnblogs.com/livelihood/p/6557944.html
Copyright © 2020-2023  润新知