本文整理汇总了Java中android.bluetooth.BluetoothSocket.close方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothSocket.close方法的具体用法?Java BluetoothSocket.close怎么用?Java BluetoothSocket.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothSocket
的用法示例。
在下文中一共展示了BluetoothSocket.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectDevice
import android.bluetooth.BluetoothSocket; //导入方法依赖的package包/类
/**
* 连接蓝牙(2)
*
* @return
*/
public static BluetoothSocket connectDevice(final Handler handler) {
BluetoothSocket socket = null;
try {
Comment.SPP_UUID = UUID.fromString("00001106-0000-1000-8000-00805F9B34FB");
socket = Comment.bluetoothDevice.createRfcommSocketToServiceRecord(Comment.SPP_UUID);
socket.connect();
handler.sendEmptyMessage(Comment.CONNECT);
} catch (Exception e) {
handler.sendEmptyMessage(2);
try {
if (socket!=null)
socket.close();
} catch (Exception closeException) {
}
}
return socket;
}
示例2: run
import android.bluetooth.BluetoothSocket; //导入方法依赖的package包/类
@Override
public void run() {
BluetoothSocket socket = null;
while (started) {
String macAddress = null;
try {
// This will block until there is a connection
Log.d(TAG, "Bluetooth Classic server is listening for a client");
socket = serverSocket.accept();
macAddress = socket.getRemoteDevice().getAddress();
if (!openConnections.containsKey(macAddress)) {
openConnections.put(macAddress, true);
StreamSync.bidirectionalSync(socket.getInputStream(), socket.getOutputStream());
}
socket.close();
} catch (IOException connectException) {
Log.e(TAG, "Failed to start a Bluetooth Classic connection as a server", connectException);
try {
if (socket != null)
socket.close();
} catch (IOException closeException) {
Log.e(TAG, "Failed to close a Bluetooth Classic connection as a server", closeException);
}
}
if (macAddress != null)
openConnections.remove(macAddress);
}
}