2

I am writing an application that relies on the Android device (for my current testing purposes an HTC Evo 4G and several original Motorola Droids) being discoverable via bluetooth for 300 seconds.

I am targeting Android version 2.0.1, so according to the API I should be able to prompt the user to enable discoverability for a maximum of 300 seconds. On both my Droids and my Evo the prompt window has 300 seconds listed, but they both end after 120 seconds.

The code I used to prompt the user is here:

private void makeDiscoverable() {
    Intent discoverableIntent = new Intent(
            BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(
            BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
    startActivity(discoverableIntent);
}

I am certain that this code runs. However, I later have a handler for when my discoverability status changes (in this case ends, I assume) that reads like this:

if (isDiscoverableChange(action)) {
            int discoverState = intent.getIntExtra(
                    BluetoothAdapter.EXTRA_SCAN_MODE, Short.MIN_VALUE);
            if (isDiscoverableState(discoverState)) {
                setItOrder();
                setUpScanAndDisplay();
            } else {
                discoverScheduler.cancel();
                itScheduler.cancel();
            }
        }

private boolean isDiscoverableChange(String action) {
    return BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action);
}

private boolean isDiscoverableState(int state) {
    return state == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
}

I tried commenting out the portion that runs when discoverability mode ends, just in case it was cancelling everything prematurely, but discoverability really does end after 120 seconds.

Is this a hardware issue, or am I doing something wrong here?

  • Are you sure that you are targeting Android 2.0.1 - I don't think there is such a thing. – Tom Jun 06 '12 at 02:00
  • Such a thing as version 2.0.1, or such a thing as hardware restrictions on maximum discoverability time? 2.0.1 is the firmware version I see in settings, which should be Eclaire, revision 1, or API Level 6 – user1438560 Jun 06 '12 at 02:06

2 Answers2

1

It appears to be a bug:

Issue 15486: Bluetooth Adapter.EXTRA DISCOVERABLE not obeyed http://code.google.com/p/android/issues/detail?id=15486

Issue 13361: BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION intent Extra does not extend 120 sec discovery interval http://code.google.com/p/android/issues/detail?id=13361

First reported Dec 22, 2010, still listed as 'new' status, so I wouldn't expect this to be fixed.

Tom
  • 17,103
  • 8
  • 67
  • 75
1

There is bluetooth DiscoverableTimeout value besides Android timeout.

Usually, DiscoverableTimeout is set in file /system/etc/bluetooth/main.conf to 120 .

You should write

DiscoverableTimeout = 0

in /system/etc/bluetooth/main.conf to disable bluetooth timeout. This will allow you to extend Android timeout over than 120 sec.

bluish
  • 26,356
  • 27
  • 122
  • 180
  • Alternatively, you can use hide method `setDiscoverableTimeout` of `BluetoothAdapter` class to set `DiscoverableTimeout = 0` – Evgeny Romanov Dec 13 '12 at 15:59