当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothSocket.close方法代码示例

本文整理汇总了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;
}
 
开发者ID:aiyangtianci,项目名称:BluetoothAPP,代码行数:24,代码来源:BluetoothUtil.java

示例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);
    }
}
 
开发者ID:aarmea,项目名称:noise,代码行数:31,代码来源:BluetoothSyncService.java


注:本文中的android.bluetooth.BluetoothSocket.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。