7

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?
Makoto
  • 104,088
  • 27
  • 192
  • 230
Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52
  • 1
    If you have the source, you could use some private api to turn bluetooth discoverable directly every 300 seconds. However I don't really know if it is possible and how to do this. – Jan S. Jul 06 '10 at 23:26
  • I can actually change a few values in the source code and (theoretically) turn off the 300 second timer altogether. Unfortunately, I'm having a multitude of problems compiling which is why I'm looking for an alternative here. However, if I can get it to compile and my first idea fails, then that is a very reasonable solution. I'll keep it in mind, thank you! – Dylan Knowles Jul 07 '10 at 15:25
  • But by turning off the 300 second timer do you mean that users would need your custom rom? – Jan S. Jul 07 '10 at 15:37
  • Since this a research project, we (myself and the other researchers) are distributing our own phones, each of which will have the custom rom. – Dylan Knowles Jul 07 '10 at 15:48
  • Oh, then I think that would be the best option. – Jan S. Jul 07 '10 at 16:16
  • I'm asking this on other forums as well; if I get a response that works, I'll post it here. – Dylan Knowles Jul 08 '10 at 20:18
  • Deat Kanov , Discoverable (make own device discoverable for other) and Do Discovery for other devices both are different things. . .the link you posted related to make own device discoverable for other devices for unlimted time . .these days I am also searching regarding these both solutions -:)P – aftab Jun 21 '11 at 15:10
  • @Kanov-baekonfat, have u got the solution till now? – Abdul Wahab Aug 01 '11 at 13:05
  • @Aftab, same question for u, as in above comment? – Abdul Wahab Aug 01 '11 at 13:11

2 Answers2

8

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);
ShadowScripter
  • 7,314
  • 4
  • 36
  • 54
gymshoe
  • 7,495
  • 5
  • 20
  • 21
  • This was not available in Android 2.1. It was available at least since Android 4, so on newer devices, yes, this is a solution. – Dylan Knowles Jun 11 '12 at 17:04
  • The docs say it was added in `android-5`, so it should be 2.0 and above: http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#EXTRA_DISCOVERABLE_DURATION – Hans-Christoph Steiner Feb 15 '14 at 00:55
  • it will still give the user dialog confirmation, @gymshoe.... not the solutions i guess – gumuruh Jul 13 '14 at 09:32
0

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.

Guntram
  • 961
  • 14
  • 19
  • 1
    BTW how can you use, it is not recognizable dear – Chatar Veer Suthar Jul 26 '11 at 09:37
  • In many version of Android this method restricts discoverability to a few minutes. – Dylan Knowles Jan 30 '12 at 17:53
  • "BTW how can you use, it is not recognizable dear" what do you mean by "not recognizable" ?? this method is definitely held by this class. it is marked as @hide. you can invoke hidden methods... here is an example http://stackoverflow.com/questions/3462968/how-to-unpair-bluetooth-device-using-android-2-1-sdk/6181809#6181809 – Guntram Apr 03 '14 at 12:39