Android蓝牙2.0开发

本文记录了一个Android应用与2.0蓝牙模块连接的步骤,包括注册广播接收蓝牙状态,获取并初始化BluetoothAdapter,搜索蓝牙设备,进行配对以及最终建立连接。
摘要由CSDN通过智能技术生成

因项目需要,做一个与2.0蓝牙模块连接的Demo,在此记录一下

1.先注册个广播,来接收一下蓝牙的状态

MyBroadCastRevciver broadcastReceiver = null;
public void registerBroadcast(){
    broadcastReceiver = new MyBroadCastRevciver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
    intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    registerReceiver(broadcastReceiver, intentFilter);
}


private String mac;
class MyBroadCastRevciver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            switch (intent.getAction()) {
                case BluetoothDevice.ACTION_FOUND:
                    Log.d("TAG", "找到蓝牙");
                    BluetoothDevice device 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值