0

特定の名前 (「SC_0001」、「SC_0002」など) を持つすべての Bluetooth デバイスをスキャンし、自動的に携帯電話とペアリングする方法を探しています。

ペアリングされたすべてのデバイスを一覧表示し、ユーザーがいずれかを選択できるようにするアプリを既に作成しました。しかし、ユーザーがこれらすべてのデバイスを手動でペアリングする必要はありません (時間がかかりすぎます)。

4

1 に答える 1

1

getname() のドキュメントによるとgetname()、BluetoothDevice クラスのメソッドを使用できます。

リモート デバイスのわかりやすい Bluetooth 名を取得します。

ローカル アダプタは、デバイス スキャンの実行時にリモート名を自動的に取得し、それらをキャッシュします。このメソッドは、キャッシュからこのデバイスの名前を返すだけです。

次に、メソッドを使用して両方の文字列を比較しますstr1.equals(str2)
編集 1
これが方法です。ペアリングされていないデバイスのリストを取得できます。

                         public void onReceive(Context context, Intent intent) {
                         String action = intent.getAction();

                         // When discovery finds a device
                         if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                             // Get the BluetoothDevice object from the Intent
                             BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                             // If it's already paired, skip it, because it's been listed already
                             if (device.getBondState() != BluetoothDevice.BOND_BONDED) 
                             {
                                // compare device.getName() and your string here, if satisfied, add them to the list-view.
                                 tv.setText(device.getName() + "\n" + device.getAddress());

ここにドキュメントへのリンクがあります。Bluetooth デバイス

于 2016-03-09T12:54:10.253 に答える