本文整理匯總了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);
}
}