测试我的设备是否可在Android上被发现

bja*_*jar 12 android bluetooth

我想在发送提示用户打开它的意图之前测试我的android设备是否可被发现,我该怎么办?

意图如下:

Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 30);
startActivityForResult(intent, idBlueToothDiscoveryRequest);
Run Code Online (Sandbox Code Playgroud)

bja*_*jar 11

我发现:

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);
}
Run Code Online (Sandbox Code Playgroud)