블루투스 응용 프로그램을 개발 중입니다. 내 응용 프로그램에서 다음 코드가 있습니다. 블루투스가 꺼져있을 때 블루투스에서 내 else 문을 바꿔서 장치 목록을 발견하면 (잘 작동 함) 그렇지 않으면 명령문이 실행되어 장치 목록을 가져옵니다.블루투스 검색이 작동하지 않습니다.
My problem is "if condition is runnning but it doesn't discover the devices"
. 누구나 해결책을 제안 할 수 있습니다.
if (btAdapter.isEnabled()) {
registerReceiver(ActionFoundReceiver, new IntentFilter(
BluetoothDevice.ACTION_FOUND));
btAdapter.startDiscovery();
} else {
Intent i1 = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(i1);
new java.util.Timer().schedule(new java.util.TimerTask() {
@Override
public void run() {
registerReceiver(ActionFoundReceiver, new IntentFilter(
BluetoothDevice.ACTION_FOUND));
btAdapter.startDiscovery();
}
}, 5000);
}
는 // 수신 장치 코드를 탐지 여기 가정
private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
items += device.getName() + ",";
}
Toast.makeText(getApplicationContext(), items, Toast.LENGTH_LONG)
.show();
}
};
덕분에 ... 이미 위의 링크를 참조 ... – Aravin
아무것도 일어나지 ... 조건없는 장치 검색 목록 경우 ... 같은 condition..in 경우 내 문제에 . – Aravin