Page 581 - MDP2020-1
P. 581
················································································ 명장양성프로젝트 【MDP】 과제발표회 자료집 Ⅰ | 575
Toast.makeText(getApplicationContext(), "페어링된 장치가 없습니다.",
Toast.LENGTH_LONG).show();
}
}
else {
Toast.makeText(getApplicationContext(), "블루투스가 비활성화 되어 있습니다.",
Toast.LENGTH_SHORT).show();
}
}
void connectSelectedDevice(String selectedDeviceName) {
for(BluetoothDevice tempDevice : mPairedDevices) {
if (selectedDeviceName.equals(tempDevice.getName())) {
mBluetoothDevice = tempDevice;
break;
}
}
try {
mBluetoothSocket =
mBluetoothDevice.createRfcommSocketToServiceRecord(BT_UUID);
mBluetoothSocket.connect();
mThreadConnectedBluetooth = new
ButtonActivity.ConnectedBluetoothThread(mBluetoothSocket);
mThreadConnectedBluetooth.start();
mBluetoothHandler.obtainMessage(BT_CONNECTING_STATUS, 1,
-1).sendToTarget();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "블루투스 연결 중 오류가 발생했습니
다.", Toast.LENGTH_LONG).show();
}
}
private class ConnectedBluetoothThread extends Thread {
private final BluetoothSocket mmSocket;
private final InputStream mmInStream;
private final OutputStream mmOutStream;
public ConnectedBluetoothThread(BluetoothSocket socket) {
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;