Reputation: 11
I'm developing an Android app that has to exchange some data through BT by automatically create a communication between two devices. To do so the only way (I've found) is to first make the device find each other and then negotiate a master who will open a ServerSocket and host the connection.
My problem then is how to toggle BT discoverability without prompting the request to the user!
I've searched the net with no success, so I start thinking about possible solution.
First I thought about something like a BroadcastReceiver that would catch the request instead the default activity launched by StartActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE))
, but then I wouldn't know what to do to actually make the device discoverable.
Recently I've thought about hiding or dismissing the dialog raised by the precedent call by automatically selecting the positive button. Once again I've no clue on how to do it!
Any help will be really appreciate, thank you in advance to everyone and sorry for my bad English!
Upvotes: 1
Views: 793
Reputation: 700
You can call .enable()
on an instance of BluetoothAdapter
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.enable();
Upvotes: 0
Reputation: 30845
I can't point to any explicit documentation, but I'm pretty sure you're not allowed to silently turn on and off Bluetooth in android. Bluetooth discoverability is something that at the end of the day is always up to the user. To subvert their authority presents a huge security concern.
Upvotes: 1