藍芽通訊神器,藍芽通訊神

來源:互聯網
上載者:User

藍芽通訊神器,藍芽通訊神

:http://download.csdn.net/detail/yoyo_newbie/8799549


執行個體代碼:

//初始化SamBluetoothManager,可在application初始化SamBluetoothManager.getInstance().init(this);//設定串連,記住配置UUIDSamBluetoothManager.getInstance().connectBluetoothDevice(address, UUID, this);//設定心跳為2秒,不設定預設為3秒SamBluetoothManager.getInstance().setHeartBeat(2*1000);//監聽心跳資訊SamBluetoothManager.getInstance().setHeartbeatListener(new SamBluetoothManager.HeartbeatListener() {@Overridepublic void outline() {nameView.setText(address+"正在重練。。。");stateView.setText(address+"離線");//重練SamBluetoothManager.getInstance().reConnect(BluetoothActivity.this);}@Overridepublic 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() {@Overridepublic void getData(byte[] data, int len) {String result =new String(data,0,  len);stateView.setText("收到一條資訊:"+result);}});



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.