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

时间:2012-08-13 13:10:12

标签: android bluetooth

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

意图如下:

Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 30);
startActivityForResult(intent, idBlueToothDiscoveryRequest);

1 个答案:

答案 0 :(得分:10)

我发现了:

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);
}