當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。