0

As I read from discussion on http://code.google.com/p/android/issues/detail?id=6348#makechanges , We can make Android Bluetooth Discoverable for unlimited time,I see that honeycomb 3.1 now publically available ,Anyone can explain using honeycomb 3.1 Development environment how I can make Bluetooth constantly discoverable ? I explore the docs but can't find any suitable method for my solution . . Thanks in advance . .

aftab
  • 1,141
  • 8
  • 21
  • 40

4 Answers4

1
You can try this:
try {
Method bluetoothDeviceVisibility;
bluetoothDeviceVisibility = mBluetoothAdapter.getClass().getMethod("setScanMode", int.class, int.class);
bluetoothDeviceVisibility.invoke(mBluetoothAdapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, 0);

} catch (Exception e) {
e.printStackTrace();
}
Dhruv
  • 91
  • 7
1

I believe that BluetoothAdapter.startDiscovery() keeps the bluetooth adapter discoverable until you call BluetoothAdapter.cancelDiscovery().

ahodder
  • 11,353
  • 14
  • 71
  • 114
  • 1
    Dear Aedon thanks for quick reply ,but if you read the doc(API) for this method there is also mentioned this > "Start the remote device discovery process.The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth nam" . Note is do the discovery for 12 minutes.my 2nd issue is how to make my device visible(discoverable for other devices) for other devices for unlimited time ? – aftab Jun 21 '11 at 14:54
  • I'm not sure about 3.0, but 2.1, 2.2, and 2.3 are time-limited. – BonanzaDriver Jun 21 '11 at 15:09
  • I see a method given on discussion on >http://stackoverflow.com/questions/3190623/make-bluetooth-on-android-2-1-discoverable-indefinitely , As public void setDiscoverableTimeout(int timeout) you can set Discoverable Time manually . .I will try this solution,my second issue regarding to make bluetooth discoverable (visible for other devices) for unlimited time . . right now we can just make it visible for max 300Sec=5 min. . . .Anyone can explain how I can make bluetooth visible for unlimited time . .Thanks – aftab Jun 21 '11 at 15:31
  • @Aftab - Ya your right, my bad. Well I was looking through the source, an I think I may have found a way but unfortunately, developers can't access it. Aside from recompiling your OS I can't think of another way to do it. – ahodder Jun 21 '11 at 15:32
0

Following intent should do it.

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

'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.'

Source: http://developer.android.com/guide/topics/connectivity/bluetooth.html

Alok Vaish
  • 922
  • 8
  • 14
-2

inside the broadcast receiver:

if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
                    // When discovery is finished, change the Activity title
                    Log.d("***","Discovery finished");
                    mBluetoothAdapter.startDiscovery();
                    Log.d("","starting discovery..");
}

its not the perfectly solution but it works for my needs

brux
  • 3,197
  • 10
  • 44
  • 78