ibeacon - How to work with Android Beacon -
i have tried this, able scan devices not able calculate major , minor using android core classes.
i have tried this
public class tagbluetooth { private context context; private list uuidlist; private itagble itagble; private bluetoothmanager bluetoothmanager; private bluetoothadapter bluetoothadapter; private bluetoothlescanner bluetoothlescanner; private final int request_enable_bt = 101; private boolean mscanning; private handler handler; // stops scanning after 10 seconds. private static final long scan_period = 10000; private bluetoothadapter.lescancallback lescancallback; private list list; public tagbluetooth(itagble activity){ this.context= (context) activity; itagble=activity; } public tagbluetooth(itagble activity,list list){ this.context= (context) activity; itagble=activity; uuidlist=list; } /** * initialize ble component */ public void initialize(){ if (isbleavailable()) { bluetoothmanager = (bluetoothmanager) context.getsystemservice(context.bluetooth_service); bluetoothadapter = bluetoothmanager.getadapter(); handler = new handler(); lescancallback = new bluetoothadapter.lescancallback() { @override public void onlescan(bluetoothdevice device, int rssi, byte[] scanrecord) { itagble.onscancomplete(device,rssi,scanrecord); } }; } checkbluetoothstatus(); } /** * ensures bluetooth available on device , enabled. if not, * displays dialog requesting user permission enable bluetooth. * * @return true device bluetooth available , false bluetooth not available */ private void checkbluetoothstatus() { if (bluetoothadapter == null || !bluetoothadapter.isenabled()) { intent enablebtintent = new intent(bluetoothadapter.action_request_enable); context.startactivity(enablebtintent); } } /** * ebale , disable ble devices scanning * * @param enable */ public void scanledevice(final boolean enable) { if(!isbleavailable()) return; if (enable) { // stops scanning after pre-defined scan period. handler.postdelayed(new runnable() { @override public void run() { mscanning = false; bluetoothadapter.stoplescan(lescancallback); } }, scan_period); mscanning = true; bluetoothadapter.startlescan(lescancallback); } else { mscanning = false; bluetoothadapter.stoplescan(lescancallback); } } /** * use check determine whether ble supported on device. * can selectively disable ble-related features. * * @return true ble support , false ble unsupported */ private boolean isbleavailable() { if (!context.getpackagemanager().hassystemfeature(packagemanager.feature_bluetooth_le)) { itagble.showmessage("ble not supported"); return false; } return true; }
}
requirement:
- scan beacon devices (including different manufacturer).
- track entry , exit beacon.
- minor , major ranging.
- scan device application closed.
if 1 me on this, wold grate me. in advance.
Comments
Post a Comment