2012-03-19 14 views
2

Bluetoothの検出がオンかどうかを検出しますか? それは可能ですか?上記のコードBluetoothディスカバリが検出されていますか?

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

はBlutoothのディスク状態をdiabling /有効にする方法についてですが、あなたが探している何をすべきbluetoothのディスコ状態

+0

「Bluetooth検出がオンかオフか」というときは、デバイスが検出可能かどうか、または検出中かどうか、つまり他のデバイスを検出していますか? – mfrankli

答えて

0
bluetoothAdapter.isDiscovering(); 

表示されません。あなたはAndroid BluetoothAdapter docでこれらのメソッドの両方を読むことができ

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 

:あなたは経由して、デフォルトBluetoothAdapterオブジェクトを取得することができます。

+0

bluetoothAdapter.isDiscovering()でエラーを返します。 – Ata

+0

エラーメッセージを見なければ、私は確認することはできませんが、私の推測では、あなたがbluetoothAdapter.isEnabled()が真であることを確認する必要があるということです - また、そのドキュメントでカバー。あなたはエラーを投稿できますか? – mfrankli

4

Bluetoothデバイスが(照会スキャン状態で)発見された場合、次のように、getScanMode()を使用し、見つけるために:

BluetoothAdapter bAdapter = BluetoothAdapter.getDefaultAdapter(); 
if(bAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { 
    // device is discoverable & connectable 
} else { 
    // device is not discoverable & connectable 
} 

Documentation of getScanMode()

int型android.bluetoothを。 BluetoothAdapter.getScanMode()

ローカルBluetoothアダプタの現在のBluetoothスキャンモードを取得します。ローカルアダプタが 接続および/またはリモートBluetoothデバイスから発見された場合

ブルートゥーススキャンモードが決定されます。

関連する問題