: http://download.csdn.net/detail/yoyo_newbie/8799549
Instance code:
Initialize the Sambluetoothmanager, initialize the Sambluetoothmanager.getinstance () in application. Init (this);//Set connection, Remember to configure Uuidsambluetoothmanager.getinstance (). Connectbluetoothdevice (Address, UUID, this);//Set the heartbeat to 2 seconds, Do not set the default to 3 seconds Sambluetoothmanager.getinstance (). Setheartbeat (2*1000);//monitor Heartbeat Information sambluetoothmanager.getinstance (). Setheartbeatlistener (New Sambluetoothmanager.heartbeatlistener () {@Overridepublic void outline () {Nameview.settext ( Address+ "is being re-practiced ... "); Stateview.settext (address+" Offline ");//re-practice sambluetoothmanager.getinstance (). Reconnect (Bluetoothactivity.this);} @Overridepublic void Online () {//Online ... nameview.settext (address+ "connected successfully!"); Stateview.settext (address+ "online");}); Send a message//sambluetoothmanager.getinstance (). SendMessage ("ddd", new Sambluetoothmanager.sendmessagecallback () {// @Override//public void Onfinished (Boolean issuccessfull) {////issuccessfull is sent successfully//}//});// Set the Listener Information Sambluetoothmanager.getinstance (). Setonrecievelistener (New Sambluetoothmanager.onrecievelistener () {@ overridepublic void GetData (byte[] data, inT len) {string result =new string (data,0, Len); Stateview.settext ("received a message:" +result);});
Bluetooth communication artifact