24

Google Android 2.1 を使用して、その地域で利用可能な Bluetooth デバイスのリストを取得する必要があります。

つまり、これらのデバイスのリストだけでなく、見つかったデバイスごとに一意の ID が必要であり、信号がどの程度「良好」に受信されているか (android.wifi.ScanResult の「レベル」など) のインジケーターが必要です。 )... それ、どうやったら出来るの?

4

4 に答える 4

52

以下のコードをチェックしてください:

検索の開始

mBluetoothAdapter.startDiscovery(); 
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    //Finding devices                 
    if (BluetoothDevice.ACTION_FOUND.equals(action)) 
    {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // Add the name and address to an array adapter to show in a ListView
       mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
    }
  }
};

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
registerReceiver(mReceiver, filter);
于 2012-05-28T09:59:40.257 に答える