BlueTooth----蓝牙

官方文档

Provides classes that manage Bluetooth functionality, such as scanning for devices, connecting with devices, and managing data transfer between devices. The Bluetooth API supports both “Classic Bluetooth” and Bluetooth Low Energy.
提供管理蓝牙功能的类,例如对设备的扫描,连接设备,和管理设备之间的数据传输。蓝牙API支持经典蓝牙和低功耗蓝牙。
For more information about Classic Bluetooth, see the Bluetooth guide. For more information about Bluetooth Low Energy, see the Bluetooth Low Energy (BLE) guide.
对于更多关于经典蓝牙信息,请看蓝牙指南对于更多关于蓝牙低耗,请查看蓝牙低耗指南

蓝牙API允许应用:

1.对于其他的蓝牙设备的扫描(包括BLE设备)
2.为配对的蓝牙设备查询本地蓝牙适配器
3.建立RFCOMM channels/sockets.(蓝牙传输协议)
4.连接在其它设备上指定的sockets
5.与其它设备之间传输数据
6.与BLE设备交流,例如接近传感器,心率监视器,健身设备,等等
7.作为GATT客户端或GATT服务端

To perform Bluetooth communication using these APIs, an application must declare the BLUETOOTH permission. Some additional functionality, such as requesting device discovery, also requires the BLUETOOTH_ADMIN permission.

使用这些蓝牙API去做蓝牙交流,一个应用必须声明蓝牙权限,其他额外的功能:如请求设备发现,也需要蓝牙权限

提示:不是所有的Android设备都提供了Bluetooth功能。

6.0之前

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

6.0之后需要动态申请

<!-- Android6.0 蓝牙扫描才需要-->
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/>


//判断是否有权限
if (ContextCompat.checkSelfPermission(this,
        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//请求权限
      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
            MY_PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION);
//判断是否需要 向用户解释,为什么要申请该权限
    if(ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.READ_CONTACTS)) {
        Toast.makeText(this, "shouldShowRequestPermissionRationale", Toast.LENGTH_SHORT).show();
    }
}

接口

BluetoothAdapter.LeScanCallback(使用le扫描蓝牙结果回调)
BluetoothProfileBluetooth Profiles(常见的蓝牙配置文件)的公共APIs
BluetoothProfile.ServiceListenerBluetoothProfile IPC 客户端与service的连接和断开时的一个通知接口

BluetoothA2dp这个类提供公共的API去控制蓝牙A2dp 配置文件
BluetoothAdapter代表本地蓝牙适配器,代表本设备
BluetoothAssignedNumbers蓝牙分配号码
BluetoothClass代表一个Bluetooth类,它描述了设备的一般特征和能力
BluetoothClass.Device定义所有设备的常量
BluetoothClass.Device.Major定义所有重要设备的常量
BluetoothClass.Service定义所有服务类的常量
BluetoothDevice代表一个远程蓝牙设备
BluetoothGatt蓝牙GATT Profile(在蓝牙连接之上的发送和接收很短的数据段的通用规范)的公共APIs
BluetoothGattCallback这个抽象类用于实现BluetoothGatt回调
BluetoothGattCallback这个抽象类用于实现BluetoothGatt回调
BluetoothGattCharacteristic代表一个Bluetooth GATT Characteristic.一个GATT Characteristic是用来构造一个GATT service,BluetoothGattService的基本数据元素
BluetoothGattDescriptor代表一个Bluetooth GATT Descriptor.GATT Descriptor包含一个GATT characteristic,BluetoothGattCharacteristic的额外信息和属性.
BluetoothGattServerBluetooth GATT Profile服务器角色的公共APIs.
BluetoothGattServerCallback这个抽象类用于实现BluetoothGattServer回调.
BluetoothGattService代表一个Bluetooth GATT Service.
BluetoothHeadset控制蓝牙耳机(Headset)服务的公共API.
BluetoothHealth蓝牙Health Profile的公共API.
BluetoothHealthAppConfigurationThe Bluetooth Health Application Configuration(配置)用来与BluetoothHealth类结合.
BluetoothHealthCallback用于实现BluetoothHealth回调的抽象类
BluetoothManager用来获取BluetoothAdapter的实例的管理者,进行全面的蓝牙管理
BluetoothServerSocket一个监听蓝牙的socket
BluetoothSocket一个已连接或正在连接的蓝牙socket.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值