android - Using fetchUuidsWithSdp() to prevent friendly name caching -
definition:
my non-android device (nad) bluetooth device loops name 60 0 , resets in infinite fashion.
objective: i'm trying have android device closely possible detect countdown , initiate alarm close of nad counter possible.
i'm doing getting native bluetoothadapter of device startdiscovery() manually tying function onscreen buttons , keeping eye on toasts set through broadcastreceiver, updates onscreen textviews enables me monitor device receiving in real-time
requirement: system & resource efficiency not concern in context.
problem:(keep eye out part 1 , part 2 in code) i'm not sure how using fetchuuidswithsdp() helping me since textview it's updating remains empty , textview getting populated extra_name intent returning action action_name_changed cached, initial discovery name (ie. application not reading name after initial discovery).
my code can found below
sorry newbie mistakes,i'm trying best :)
public class btbroadcastreceiver extends broadcastreceiver{ @override public void onreceive(context context, intent intent) { //pulling action name broadcasted intent string action = intent.getaction(); if(bluetoothadapter.action_discovery_started.equals(action)){ stoaster("startedd");//show toast discovery has started } else if(bluetoothadapter.action_discovery_finished.equals(action)){ stoaster("endedd");//show toast signifying end of discovery /* if(notfound){ mbtadapter.startdiscovery(); }*/ } else if(bluetoothdevice.action_found.equals(action)){ //when device found bluetoothdevice device = intent.getparcelableextra(bluetoothdevice.extra_device); //make sure it's indeed nad device checking mac address if(device.getaddress().equals(macaddress)){ if(notfound){ //show device name on screen stoaster("found device"); notfound = false; nad = device; nameshower.settext(device.getname()); } else{ //do nothing if it's second time device found } } } else if(bluetoothdevice.action_name_changed.equals(action)){ //name changed bluetoothdevice founddevice = intent.getparcelableextra(bluetoothdevice.extra_device); //make sure it's indeed nad device if(founddevice.equals(nad)){ stoaster("name change!"); //show on screen name change intent has been caught //part1 //to prevent caching of old device name stackoverflow article //advised using function don't totally understand yet //nad.fetchuuidswithsdp(); //either commented or not commented outcome same (no refresh of name) //part2 //tried showing new name 2 different ways below, neither of effective //by inspecting textviews on-screen nameshower.settext(founddevice.getname()); eventview.settext(intent.getstringextra(bluetoothdevice.extra_name)); } } } };
i have worked on bluetooth project , perceived discovery process should in intent can left registered in background. , discover devices in range, need invoke btdevice.startdiscovery() search them. startdiscovery() drains battery if enabled continuously. if want, can edit post share snipet used scan devices. hope helps !
Comments
Post a Comment