使Android 2.1上的蓝牙无限期可被发现

我正在研究涉及蓝牙和Android操作系统的研究项目.我需要无限期地发现蓝牙,以便项目继续进行.

问题:

> Android将可发现性限制为300秒.
>我不能要求用户每隔300秒重新开启可发现性,因为我的应用程序旨在在后台运行而不会打扰用户.
>据我所知,没有办法通过Android的GUI增加时间.一些消息来源称这是一个安全功能,其他人称这是一个错误.两者都可能有一些道理……

我正在尝试/尝试过:

>我正在尝试编辑cyanogenmod的稳定版本以关闭可发现性计时器(这是可能的;有一个配置文件需要更改一个数字).这不起作用,因为我对生成的包有验证问题.
>在过去的一周里,我下载了cyanogenmod source code,更改了一个相关的类,希望它能无限发现蓝牙,并尝试recompile.这没有用,因为(a)repo经常更改,导致代码库不稳定无法编译(或者,可能是我错误地使用它;只是因为在许多情况下它看起来像代码的错误并不意味着我应该为我遇到的所有问题归咎于它!)和(b回购决定定期“忽略”我(但并不总是,因为我之前已经获得了代码库!),回复我的同步/连接尝试:

fatal: The remote end hung up unexpectedly

正如您可能想象的那样,上述两个问题是有问题的,并且处理起来非常令人沮丧.
更多信息:

>我通过cyanogenmod运行Android 2.1(我相信v5).这意味着手机也已植根.
>我有一个开发人员手机,这意味着引导加载程序已解锁.
>我的手机是HTC Magic(32B).

大问题:

>如何在Android上无限制地发现蓝牙?

解决方法:

请参阅以下链接:
http://developer.android.com/guide/topics/wireless/bluetooth.html#ConnectingDevices

具体而言,下段中的最后一句:

Enabling discoverability
If you would like to make the local device discoverable to other devices, call startActivityForResult(Intent, int) with the ACTION_REQUEST_DISCOVERABLE action Intent. This will issue a request to enable discoverable mode through the system settings (without stopping your application). By default, the device will become discoverable for 120 seconds. You can define a different duration by adding the EXTRA_DISCOVERABLE_DURATION Intent extra. The maximum duration an app can set is 3600 seconds, and a value of 0 means the device is always discoverable.

所以,这应该工作:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivity(discoverableIntent);
上一篇:android BluetoothDevice.getName()返回null


下一篇:如何在Android中发送基于BT免提配置文件的AT命令?