Android Application Bluetooth visibility duration

2019-04-16 17:44发布

Is there a way to let my application be discoverable for a time the app is running? I tried to do this with

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivityForResult(discoverableIntent, DISC_DURATION);

as shown on Android Developers, but the Duration of 0 doesn't work so the default value 120 is set. Is there a way to set it as visible all the time?

3条回答
淡お忘
2楼-- · 2019-04-16 17:47

I come to the conclusion on three devices I have.

ANDROID v 4.3 and higher : EXTRA_DISCOVERABLE_DURATION 0 works no limit ANDROIND v 4.1 : EXTRA_DISCOVERABLE_DURATION 0 is max 1 hour. Have to change manually to no limit in parameters.

查看更多
Deceive 欺骗
3楼-- · 2019-04-16 17:58

there is no mean for keep Bluetooth discoverable all time. At the time when you want to find some new devices or other devices can find your device you have to make it discoverable. After that your device will interchange a shared MAC id and will make a paired.

Performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources. Once you have found a device to connect, be certain that you always stop discovery with cancelDiscovery() before attempting a connection. Also, if you already hold a connection with a device, then performing discovery can significantly reduce the bandwidth available for the connection, so you should not perform discovery while connected.

for more info see this

http://developer.android.com/guide/topics/wireless/bluetooth.html#DiscoveringDevices

查看更多
爷、活的狠高调
4楼-- · 2019-04-16 18:01

There is no way for you to set bluetooth to be continuously discoverable on any 2.* version of Android; see this bug report. It seems like the limitation has been removed in 3.* versions, but I haven't seen any confirmation of this.

查看更多
登录 后发表回答