Android's Broadcastreceiver

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.