标签:
下载地址:http://download.csdn.net/detail/yoyo_newbie/8799549
实例代码:
//初始化SamBluetoothManager,可在application初始化 SamBluetoothManager.getInstance().init(this); //设置连接,记住配置UUID SamBluetoothManager.getInstance().connectBluetoothDevice(address, UUID, this); //设置心跳为2秒,不设置默认为3秒 SamBluetoothManager.getInstance().setHeartBeat(2*1000); //监听心跳信息 SamBluetoothManager.getInstance().setHeartbeatListener(new SamBluetoothManager.HeartbeatListener() { @Override public void outline() { nameView.setText(address+"正在重练。。。"); stateView.setText(address+"离线"); //重练 SamBluetoothManager.getInstance().reConnect(BluetoothActivity.this); } @Override public void online() { //在线中... nameView.setText(address+"连接成功!"); stateView.setText(address+"在线"); } }); // //发送一条信息 // SamBluetoothManager.getInstance().sendMessage("ddd", new SamBluetoothManager.SendMessageCallback() { // // @Override // public void onFinished(boolean isSuccessfull) { // //isSuccessfull 是否发送成功 // } // }); //设置监听信息 SamBluetoothManager.getInstance().setOnRecieveListener(new SamBluetoothManager.OnRecieveListener() { @Override public void getData(byte[] data, int len) { String result =new String(data,0, len); stateView.setText("收到一条信息:"+result); } });
标签:
原文地址:http://blog.csdn.net/yoyo_newbie/article/details/46470379