android开发蓝牙是否可见开关,想要一个Android的蓝牙是始终可见,直至应用程序运行?...

I want that my bluetooth to be visible until the app is running. Like for infinite time. I will turn it off when Im done with it.

I don't want it to ask user for duration of visibility as in following method

Intent discoverableIntent = new

Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,300);

startActivity(discoverableIntent);

Please help!

解决方案

The short answer is that you can't; see this bug report. Trust me, I'm as annoyed about this as you are; it makes ad-hoc networking on Bluetooth very difficult. There are some suggestions on that thread that the limitation is gone in Honeycomb and perhaps will make it into Ice Cream Sandwich. For the moment, there is no way around it, short of installing a custom ROM.

With that said, there are some workarounds. Since Android requires pairing before any Bluetooth socket (server or client) can send data, your app can simply try and connect to already paired devices. Sure, most of the time the connection will fail, but if a paired device is in range the connection will happen. I've implemented this in an application of mine and it seems to work. I'm not sure how this affects battery life, but with enough time between scans you ought to be okay.

I'm hoping that future versions of Android won't have this unnecessary limitation as it prevents some potentially interesting ad-hoc networking applications.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值