5
사용 가능한 블루투스 기기를 찾으려고합니다.블루투스 기기 용 Android 검색
사용자가 사용 가능한 장치를 검색하려고 할 때 호출되는 내 OnClickListener입니다.
View.OnClickListener OnSearchDevices = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(context, "Search Devices", Toast.LENGTH_LONG).show();
Log.d("Discovery", "Started");
listOfDevices.clear();
label.setText("Searching Available Devices...");
label.setEnabled(false);
}
};
나는 BroadcastReceiver도 등록했습니다.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
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);
Log.d("DeviceList" , device.getName() + "\n" + device.getAddress());
MyBluetoothDevice tempDevice = new MyBluetoothDevice();
tempDevice.setDeviceAddress(device.getAddress());
tempDevice.setDeviceName(device.getName());
listOfDevices.add(tempDevice);
mListAdapter.notifyDataSetChanged();
// discovery is finished
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.d("Discovery","Finished");
label.setEnabled(true);
if(listOfDevices.size() == 0)
{
label.setText("No Devices Available!");
label.setTextColor(Color.parseColor("#FF0000"));
}
else
{
label.setText("Available Devices");
}
}
}
};
하지만 아무 일도 발생하지 않습니다. 아무것도 표시하지 않습니다. 도와주세요.
어디에 추가합니까? – user2477164
'onClick()'의 내부 – Swayam
굉장! 마술처럼 일했습니다! 너 락맨! :디 – user2477164