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


Java BluetoothSocket.connect方法代码示例

本文整理汇总了Java中android.bluetooth.BluetoothSocket.connect方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothSocket.connect方法的具体用法?Java BluetoothSocket.connect怎么用?Java BluetoothSocket.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.bluetooth.BluetoothSocket的用法示例。


在下文中一共展示了BluetoothSocket.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: create

import android.bluetooth.BluetoothSocket; //导入方法依赖的package包/类
public static RemoteItConnectionBluetooth create(ActionControl application, Context mContext, String address) throws IOException
{
	Looper.prepare();
	
	BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
	
	if (adapter != null)
	{
		if (adapter.isEnabled())
		{
			try
			{
				BluetoothDevice device = adapter.getRemoteDevice(address);
				
				if (device != null)
				{
					BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID.fromString(RemoteItConnection.BLUETOOTH_UUID));
					socket.connect();
					
					RemoteItConnectionBluetooth connection = new RemoteItConnectionBluetooth(socket);
					
					return connection;
				}
			}
			catch (IllegalArgumentException e)
			{
				throw new IOException();
			}
		}
		else
		{
			if (application.requestEnableBluetooth())
			{
				Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				mContext.startActivity(intent);
			}
		}
	}
	
	throw new IOException();
}
 
开发者ID:Elbehiry,项目名称:Pc-Control,代码行数:43,代码来源:RemoteItConnectionBluetooth.java

示例3: getSocket

import android.bluetooth.BluetoothSocket; //导入方法依赖的package包/类
public static BluetoothSocket getSocket(BluetoothDevice device) throws IOException {
	BluetoothSocket socket = device.createRfcommSocketToServiceRecord(PRINTER_UUID);
	socket.connect();
	return socket;
}
 
开发者ID:januslo,项目名称:react-native-sunmi-inner-printer,代码行数:6,代码来源:BluetoothUtil.java


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