I'm writing Android applications to find and find out about IBeacons (these are BLE devices) and taking them (based on RSSI value). I >
but this code works differently on my Android device (Samsung Galaxy S3 and LG G3).
On the "On Lessen" callback loop on my S3, increases about 5 seconds per second) and gives me RSSI values each time depending on the range separately.
But on my LG G3 the "On Lyscan" callback increases only once, when I start scanning, so if I want to get new RSSI values, then I have to restart scanning . And I think it's not very good.
I do not know whether this is something wrong with the LG G3 driver, or I should see some Android settings. Can anyone tell me something about it?
Here is my code:
Increases the implementation of the public class Main2Activity Activity BluetoothAdapter.LeScanCallback {Personal BluetoothAdapter mBluetoothAdapter; Private boolean mScanning; Private handler mHandler = new handler (); @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main2); / ** / Last Bluetooth Manager Bluetooth Manager = (Bluetooth Manager) getSystemService (Event.BULUETOOTH_SERVICE); MBluetoothAdapter = bluetoothManager.getAdapter (); If (mBluetoothAdapter == Zero ||! MBluetoothAdapter.isEnabled ()) {Intent EnableBitIntent = New Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE); EnableBtIntent.addFlags (enableBtIntent.FLAG_ACTIVITY_NEW_TASK); This.startActivity (enableBtIntent); } ScanLeDevice (true); } Private Zero Scan Lev Device (Last Boolean enabled) {if (enabled) {// Prevents scanning after pre-defined scan period. MHandler.postDelayed {New Runnabal} {@Override Public Zero Run () {mScanning = false; MBluetoothAdapter.stopLeScan (Main2Activity.This);}}, 30000); MScanning = true; MBluetoothAdapter.startLeScan (Main2Activity.this); } And {mScanning = false; MBluetoothAdapter.stopLeScan (Main2Activity.this); }} ArrayList & lt; String & gt; Datas = new ArrayList & lt; String & gt; (); Override public null at @LeScan (Bluetooth davis arg0, int arg1, byte [arg2]) {// TODO auto generated method stub datas.add (arg2.toString ()); } @ Override Public Boolean On Option It's Select (menu item) {Return Super.OnptionMeSpace (item); } @ Override Public Boolean On Crate Option Menus (Menu Menu) {Return Correct; }
Unfortunately, you have to stop and restart the scanning to get an additional callback . It is implemented in the same way that it is possible to get a callback in each cycle on how this operating system is not backing up for every ad.
It is not clear how this differs between devices and operating system versions. With Android 4.3, on Nexus 4, the scanning behavior for connectable Blue Advertising versus non-connectable blade ads was different. Connectable ads cause only one ad callback due to a scan cycle, while non-connectable ads scan multiple callbacks per cycle. This behavior can vary on other devices and OS versions, which is why cycling is necessary for wider compatibility.
On the Nexus 5 devices with Android 5.0, the new scanning API always returns many callbacks for each BLE ad. The same device, whether the ad is connectable or not. Nexus 4 devices with Android 5.0, yet, until the scan is turned off and restarted, only one advertisement callback is available for connectivity ads. It appears to be implemented at the driver level, so it can be different for each ROM image.
Comments
Post a Comment