Android Application Bluetooth visibility duration

浪尽此生 提交于 2019-12-06 17:09:28

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6899976/android-application-bluetooth-visibility-duration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!