Android Question Bluetooth Visible

mlc

Active Member
Licensed User
Longtime User
Hi all
I hope you can help me.

I need to know if my bluetooth is visible, after assigning n seconds.
I can not find this property in BluetoothAdmin.

It would be something like:

B4X:
dim admin as BluetoothAdmin
If admin.getScanMode <> admin.SCAN_MODE_CONNECTABLE_DISCOVERABLE then
    Dim i As Intent
    i.Initialize("android.bluetooth.adapter.action.REQUEST_DISCOVERABLE", "")
    i.PutExtra("android.bluetooth.adapter.extra.DISCOVERABLE_DURATION", 300)
    StartActivity(i)
end if

From developer.android.com
public int getScanMode ()
Possible values are: SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE.

• public static final int SCAN_MODE_NONE = Constant Value: 20 (0x00000014)
Therefore this device is neither discoverable nor connectable from remote Bluetooth devices.

•public static final int SCAN_MODE_CONNECTABLE = Constant Value: 21 (0x00000015)
•public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = Constant Value: 23 (0x00000017)
Indicates that both inquiry scan and page scan are enabled on the local Bluetooth adapter. Therefore this device is both discoverable and connectable from remote Bluetooth devices.

Maybe with Reflection?

Thanks
 

mlc

Active Member
Licensed User
Longtime User
Hi Erel

Thank you very much, works perfectly. I had not thought about your JavaObject.

Building on your code:

B4X:
'Get the current Bluetooth scan mode of the local Bluetooth adapter.
Log(bta.RunMethod("getScanMode", Null))
'Get the friendly Bluetooth name of the local Bluetooth adapter.
Log(bta.RunMethod("getName", Null))
'Returns the hardware address of the local Bluetooth adapter.
Log(bta.RunMethod("getAddress", Null))


Maybe it would be a good idea, to improve BluetoothAdmin, add these properties to the next version.
 
Upvote 0
Top