Android Getting continuously Bluetooth signal strength of paired devices -
i listing paired devices,and work want bluetooth signal strength of paired devices...i know use rssi cannot implement continuously in app.. plz me giving suitable code code...my code here...
public class security extends fragment implements onclicklistener{ private bluetoothadapter ba; private set<bluetoothdevice>paireddevices; arraylist<string> mylist = new arraylist<string>(); //private object imageview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.security, null); ba = bluetoothadapter.getdefaultadapter(); /* starting bluetooth*/ on(v); paireddevices = ba.getbondeddevices(); //length=4; // int j=1; for(bluetoothdevice bt : paireddevices) { mylist.add(bt.getname()); length=j; j++; bt.getbondstate(); } return v; } @override public void onresume() { super.onresume(); // toast.maketext(getactivity(), "on resume", toast.length_long).show(); } /*************************bluetooth function****************************/ public void on(view view){ if (!ba.isenabled()) { intent turnon = new intent(bluetoothadapter.action_request_enable); startactivityforresult(turnon, 0); toast.maketext(getactivity(),"turned on" ,toast.length_long).show(); } else{ // toast.maketext(getactivity(),"already on", // toast.length_long).show(); } } public void discovery(view view) { if(ba.isdiscovering()) { ba.canceldiscovery(); } } public void list(view view){ toast.maketext(getactivity(),"showing paired devices", toast.length_short).show(); } @override public void onclick(view v) { for(int j=0;j<length;j++) { if(v.getid()==j) toast.maketext(getactivity(), mylist.get(j), toast.length_long).show(); //hand.update(run,1000); } } }
you can signal following code.
code activity
@override public void oncreate(bundle savedinstancestate) { ..... // registering broadcast. fire when bluetoothdevice found registerreceiver(receiver, new intentfilter(bluetoothdevice.action_acl_connected)); } private final broadcastreceiver broadcastreceiver = new broadcastreceiver(){ @override public void onreceive(context context, intent intent) { string mintentaction = intent.getaction(); if(bluetoothdevice.action_acl_connected.equals(mintentaction)) { int rssi = intent.getshortextra(bluetoothdevice.extra_rssi,short.min_value); string mdevicename = intent.getstringextra(bluetoothdevice.extra_name); } } };
this broadcast execute when device connected remote device. there several other action on can fire broadcast. have @ here(bluetoothdevice)
check following link constant reading of rssi
tutorial continuously measure bluetooth rssi of connected android device (java)
output of link :
Comments
Post a Comment