[Source: Google native sample Bluetoothchat]
[Code function: Implement the processing of event broadcast detected by Andoran dental equipment]
[Code below]
//The broadcastreceiver that listens for discovered devices and//changes the title when discovery is finishedPrivate Final broadcastreceiver Mreceiver =NewBroadcastreceiver () {@Override Public void onreceive(context context, Intent Intent) {String action=intent.getaction ();//When Discovery finds a deviceif(bluetoothdevice.action_found. Equals (ACTION)) {//Get The Bluetoothdevice object from the IntentBluetoothdevice device =Intent.getparcelableextra (bluetoothdevice.extra_device);//If It's already paired, skip it, because it ' s been listed alreadyif(Device.getbondstate ()! =bluetoothdevice.bond_bonded) {Mnewdevicesarrayadapter.add (Device.getname ()+ "\ n" +device.getaddress ()); }//When discovery are finished, change the Activity title}Else if(bluetoothadapter.action_discovery_finished. Equals (ACTION)) {setprogressbarindeterminatevisibility (false); Settitle (r.string.select_device);if(Mnewdevicesarrayadapter.getcount () = = 0) {String nodevices=getresources (). GetText (R.string.none_found). toString (); Mnewdevicesarrayadapter.add (nodevices); }}};
Android's Broadcastreceiver