私はブルートゥース対応のアンドロイドデバイスのプログラム(複数の)をプログラムで接続する必要があります。ブルートゥースを有効にしてデバイスの番号を取得し、リストでソートしてください。アンドロイドでブルートゥース対応デバイスのリストをプログレッシブにペアリングするにはどうすればいいですか?
if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
pairAllDevice(mDeviceList);
showToast("finished");
display();
}
private void pairAllDevice(ArrayList<BluetoothDevice> data)
{
if(!pairedDevice.isEmpty()) {
pairedDevice.clear();
}
for(int i=0;i<data.size();i++)
{
pairDevice(data.get(i));
}
}
これは私が他のエンドに私のアプリケーションが自動ペアリングを受けるように、暗黙のペアリングを実施し、しかし、リストから一つだけのデバイスのために今のところその作品き
private void pairDevice(BluetoothDevice device) {
try {
Method method = device.getClass().getMethod("createBond", (Class[]) null);
method.invoke(device, (Object[]) null);
pairedDevice.add(device);
} catch (Exception e) {
Log.e("error","connecting");
e.printStackTrace();
}
}
をペアリングする機能です。