I am using the example from BLE ScanSettingsBuilder modified starter service in posting: https://www.b4x.com/android/forum/threads/ble-scansettings.94908/#post-600231
Works great .
Now I am trying to add custom ScanFilterSettings with setDeviceName as a filter but I'm not having success with the Filters array (my lack of understanding of javaobject )
This is my modified code from the example above, I'm guessing my problem is in Filters.InitializeArray.
Any help is appreciated.
Works great .
Now I am trying to add custom ScanFilterSettings with setDeviceName as a filter but I'm not having success with the Filters array (my lack of understanding of javaobject )
This is my modified code from the example above, I'm guessing my problem is in Filters.InitializeArray.
B4X:
Private Sub ScanWithLeScanner
Dim ScanSettingsStatic As JavaObject
ScanSettingsStatic.InitializeStatic("android.bluetooth.le.ScanSettings")
Dim ScanSettingsBuilder As JavaObject
ScanSettingsBuilder.InitializeNewInstance("android.bluetooth.le.ScanSettings.Builder", Null)
'https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder
ScanSettingsBuilder.RunMethod("setScanMode", Array(ScanSettingsStatic.GetField("SCAN_MODE_LOW_LATENCY")))
'----------------------------------------------------------------------
' Add Scan Filter
Dim ScanFilterStatic As JavaObject
ScanFilterStatic.InitializeStatic("android.bluetooth.le.ScanFilter")
Dim ScanFilterBuilder As JavaObject
ScanFilterBuilder.InitializeNewInstance("android.bluetooth.le.ScanFilter.Builder", Null)
'https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder
ScanFilterBuilder.RunMethod("setDeviceName", Array("B4APeripheral"))
ScanFilterBuilder.InitializeNewInstance("android.bluetooth.le.ScanFilter.Builder", Null)
Dim Filters As JavaObject
Filters.InitializeArray("android.bluetooth.le.ScanFilter",ScanFilterBuilder.RunMethod("build",Null))
'---------------------------------------------------------------------------
ScanSettingsBuilder.InitializeNewInstance("android.bluetooth.le.ScanSettings.Builder", Null)
Scanner.RunMethod("startScan", Array(Filters, ScanSettingsBuilder.RunMethod("build", Null), ScanCallback))
'Scanner.RunMethod("startScan", Array(Null, ScanSettingsBuilder.RunMethod("build", Null), ScanCallback))
End Sub
Any help is appreciated.