Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if my device is discoverable on Android

I want to test if my android device is discoverable before sending the intent that prompts the user to turn it on, what do I do?

the intent is as follows:

Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 30);
startActivityForResult(intent, idBlueToothDiscoveryRequest);
like image 805
bjar-bjar Avatar asked Aug 13 '12 13:08

bjar-bjar


People also ask

How do I check Bluetooth status on Android?

Call isEnabled() to check whether Bluetooth is currently enabled. If this method returns false, then Bluetooth is disabled. To request that Bluetooth be enabled, call startActivityForResult() , passing in an ACTION_REQUEST_ENABLE intent action.

How do you check Bluetooth is connected or not?

Make sure Bluetooth is turned on. Touch and hold Bluetooth . In the list of paired devices, tap a paired but unconnected device. When your phone and the Bluetooth device are connected, the device shows as "Connected."

How do I turn on Bluetooth visibility on Android?

From the Home screen, tap the Menu key > Settings > Bluetooth. Tap the Bluetooth switch to turn it on. Tap the check box next to your phone's name to make your phone visible to other Bluetooth devices. A list of available devices will be displayed.


1 Answers

I found out:

if(mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
{
    Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 30);
    startActivityForResult(intent, idBlueToothDiscoveryRequest);
}
like image 197
bjar-bjar Avatar answered Sep 28 '22 07:09

bjar-bjar