开发者

Make Bluetooth on Android 2.1 discoverable indefinitely

I'm working on a research project which involves Bluetooth and the Android OS. I need to make Bluetooth discoverable indefinitely in order for the project to continue.

The Problem:

  • Android limits discoverability to 300 seconds.
  • I cannot ask the user every 300 seconds to turn discoverability back on as my application is designed to开发者_高级运维 run in the background without disturbing the user.
  • As far as I am aware, there is no way to increase the time though Android's GUI. Some sources have called this a safety feature, others have called this a bug. There may be a bit of truth in both...

What I'm Trying / Have Tried:

  • I'm trying to edit a stable release of cyanogenmod to turn the discoverability timer off (it's possible; there's a configuration file that needs to have a single number changed). This isn't working because I'm having verification problems with the resulting package.
  • During the past week, I downloaded the cyanogenmod source code, changed a relevant class in the hope that it would make Bluetooth discoverable indefinitely, and tried to recompile. This did not work because (a) the repo is frequently changed, leading to an unstable code base which fails to compile (OR, it could be that I'm using it incorrectly; just because it looked like it was the code's fault in many instances doesn't mean I should blame it for all the problems I encountered!) and (b) the repo decides to periodically "ignore" me (but not always, as I have gotten the code base before!), replying to my synchronization/connection attempts with:

    fatal: The remote end hung up unexpectedly

As you might imagine, the above two issues are problematic and very frustrating to deal with.

More Info:

  • I'm running Android 2.1 via cyanogenmod (v5 I believe). This means the phone is also rooted.
  • I have a developer phone, which means that the bootloader is unlocked.
  • My phone is an HTC Magic (32B).

The Big Question:

  • How can I make Bluetooth indefinitely discoverable on Android?


See the following link: http://developer.android.com/guide/topics/wireless/bluetooth.html#ConnectingDevices

Specifically, the last sentence in the paragraph below:

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.

So, this should work:

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


If you check out the BluetoothAdapter class

you will find the hidden method:

public void setDiscoverableTimeout(int timeout)

Now you only have to find out how to use it. You have to do a method invocation to do so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜