當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothSocket類代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothSocket的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothSocket類的具體用法?Java BluetoothSocket怎麽用?Java BluetoothSocket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BluetoothSocket類屬於android.bluetooth包,在下文中一共展示了BluetoothSocket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ConnectedThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectedThread(BluetoothSocket socket, String socketType) {
    Log.d(TAG, "create ConnectedThread: " + socketType);
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
    mState = STATE_CONNECTED;
}
 
開發者ID:hardik-dadhich,項目名稱:bluetooth-chat-appliction,代碼行數:19,代碼來源:BluetoothChatService.java

示例2: 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

示例3: ConnectThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectThread(BluetoothDevice device, boolean secure)
{
    mmDevice = device;
    BluetoothSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Get a BluetoothSocket for a connection with the given BluetoothDevice
    try
    {
        if (secure)
        {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
        }
        else
        {
            tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
        }
    }
    catch (IOException e)
    {
        MyLog.e(TAG, "Socket Type: " + mSocketType + " create() failed", e);
    }

    mmSocket = tmp;
}
 
開發者ID:Mozta,項目名稱:ELM327,代碼行數:26,代碼來源:BluetoothIOGateway.java

示例4: ConnectThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectThread(BluetoothDevice device, boolean secure) {
    mmDevice = device;
    BluetoothSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Get a BluetoothSocket for a connection with the
    // given BluetoothDevice
    try {
        if (secure) {
            tmp = device.createRfcommSocketToServiceRecord(
                    MY_UUID_SECURE);
        } else {
            tmp = device.createInsecureRfcommSocketToServiceRecord(
                    MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
    }
    mmSocket = tmp;
    mState = STATE_CONNECTING;
}
 
開發者ID:AviralGarg1993,項目名稱:VR-One,代碼行數:22,代碼來源:BluetoothListener.java

示例5: bind

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
/**
 * Bind boolean.
 *
 * @param socket the socket
 * @return the boolean
 */
public boolean bind( BluetoothSocket socket )
{

	mmSocket = socket;
	macAddress = mmSocket.getRemoteDevice().getAddress();

	// Get the BluetoothSocket input and output streams
	try
	{
		mmInStream = socket.getInputStream();
		mmOutStream = socket.getOutputStream();

		this.isRunning = true;
		// 펜 연결 후 맨 처음 펜정보를 요청한다.(프로토콜 2.0)
		startConnect();
		return true;
	}
	catch ( IOException e )
	{
		NLog.e( "[BTAdt/ConnectedThread] temporary sockets is not created", e );
	}

	return false;
}
 
開發者ID:NeoSmartpen,項目名稱:AndroidSDK2.0,代碼行數:31,代碼來源:BTAdt.java

示例6: ConnectThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
/**
 * Creates the connection thread that will connect to a given device.
 *
 * @param device The device to connect to
 */
ConnectThread(BluetoothDevice device) {
    mmDevice = device;
    BluetoothSocket tmp = null;

    // Get a BluetoothSocket for a connection with the given BluetoothDevice
    try {
        tmp = device.createRfcommSocketToServiceRecord(SERVICE_UUID);
    } catch (IOException e) {
        Log.e(TAG, "create socket failed", e);
    }
    mmSocket = tmp;
    mState = ServiceState.CONNECTING;

    // Notifiy the user that we are now connecting
    android.os.Message userNotification
            = mHandler.obtainMessage(ServiceState.CONNECTING.ordinal());
    mHandler.sendMessage(userNotification);
}
 
開發者ID:FelixWohlfrom,項目名稱:Presenter-Client-Android,代碼行數:24,代碼來源:BluetoothPresenterControl.java

示例7: ConnectThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectThread(BluetoothDevice device, boolean secure) {
    mmDevice = device;
    BluetoothSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Get a BluetoothSocket for a connection with the
    // given BluetoothDevice
    try {
        if (secure) {
            tmp = device.createRfcommSocketToServiceRecord(
                    MY_UUID_SECURE);
        } else {
            tmp = device.createInsecureRfcommSocketToServiceRecord(
                    MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
    }
    mmSocket = tmp;
}
 
開發者ID:tkmarsh,項目名稱:SmartRC,代碼行數:21,代碼來源:BluetoothChatService.java

示例8: connected

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
/**
 * Start the ConnectedThread to begin managing a Bluetooth connection
 *
 * @param socket The BluetoothSocket on which the connection was made
 * @param device The BluetoothDevice that has been connected
 */
private synchronized void connected(BluetoothSocket socket, BluetoothDevice device) {
    // Cancel the thread that completed the connection
    if (mConnectThread != null) {
        mConnectThread.cancel();
        mConnectThread = null;
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
        mConnectedThread.cancel();
        mConnectedThread = null;
    }

    // Start the thread to manage the connection and perform transmissions
    mConnectedThread = new ConnectedThread(socket, this, device);
    mConnectedThread.start();
}
 
開發者ID:FelixWohlfrom,項目名稱:Presenter-Client-Android,代碼行數:24,代碼來源:BluetoothPresenterControl.java

示例9: createKeyAgreementConnection

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
@Override
public DuplexTransportConnection createKeyAgreementConnection(
		byte[] commitment, BdfList descriptor, long timeout) {
	if (!isRunning()) return null;
	String address;
	try {
		address = parseAddress(descriptor);
	} catch (FormatException e) {
		LOG.info("Invalid address in key agreement descriptor");
		return null;
	}
	// No truncation necessary because COMMIT_LENGTH = 16
	UUID uuid = UUID.nameUUIDFromBytes(commitment);
	if (LOG.isLoggable(INFO))
		LOG.info("Connecting to key agreement UUID " + uuid);
	BluetoothSocket s = connect(address, uuid.toString());
	if (s == null) return null;
	return new DroidtoothTransportConnection(this, s);
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:20,代碼來源:DroidtoothPlugin.java

示例10: acceptContactConnections

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
private void acceptContactConnections() {
	while (isRunning()) {
		BluetoothSocket s;
		try {
			s = socket.accept();
		} catch (IOException e) {
			// This is expected when the socket is closed
			if (LOG.isLoggable(INFO)) LOG.info(e.toString());
			return;
		}
		if (LOG.isLoggable(INFO)) {
			String address = s.getRemoteDevice().getAddress();
			LOG.info("Connection from " + scrubMacAddress(address));
		}
		backoff.reset();
		callback.incomingConnectionCreated(wrapSocket(s));
	}
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:19,代碼來源:DroidtoothPlugin.java

示例11: call

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
@Override
public BluetoothSocket call() throws Exception {
	// Repeat discovery until we connect or get interrupted
	while (true) {
		// Discover nearby devices
		LOG.info("Discovering nearby devices");
		List<String> addresses = discoverDevices();
		if (addresses.isEmpty()) {
			LOG.info("No devices discovered");
			continue;
		}
		// Connect to any device with the right UUID
		for (String address : addresses) {
			BluetoothSocket s = connect(address, uuid);
			if (s != null) {
				LOG.info("Outgoing connection");
				return s;
			}
		}
	}
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:22,代碼來源:DroidtoothPlugin.java

示例12: ConnectThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectThread(BluetoothDevice device) {
    // Use a temporary object that is later assigned to mmSocket,
    // because mmSocket is final
    BluetoothSocket tmp = null;
    mmDevice = device;

    /*try {
        tmp = createBluetoothSocket(device);
    } catch (IOException e1) {
        e1.printStackTrace();
    }*/

    try {
        tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
    } catch (IOException e) { e.printStackTrace(); }

    /*try {
        tmp = createBluetoothSocket(device);
    } catch (IOException e) {
        e.printStackTrace();
    }*/

    mmSocket = tmp;
}
 
開發者ID:ordsen,項目名稱:Snach-Android,代碼行數:25,代碼來源:BluetoothActivity.java

示例13: connectToClient

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
private void connectToClient(final BluetoothSocket btSocketClient) throws IOException {
    MLog.d(TAG, "bbt connection to device: " + btSocketClient.getRemoteDevice().getName());

    final ConnectedDevice connectedDevice = new ConnectedDevice(btSocketClient);
    mServerConnections.add(connectedDevice);

    // callback
    if (mCallbackOnNewConnection != null) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                ReturnObject ret = new ReturnObject();
                ret.put("device", connectedDevice);
                ret.put("name", btSocketClient.getRemoteDevice().getName());
                ret.put("mac", btSocketClient.getRemoteDevice().getAddress());
                mCallbackOnNewConnection.event(ret);
            }
        });

    }

    connectedDevice.startThread();
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:24,代碼來源:PBluetoothServer.java

示例14: ConnectThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectThread(BluetoothDevice device, boolean secure) {
    mmDevice = device;
    BluetoothSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    try {
        if (secure) {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
        } else {
            tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
        }
    } catch (IOException | NullPointerException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
    }
    mmSocket = tmp;
    mState = STATE_CONNECTING;
}
 
開發者ID:zeevy,項目名稱:grblcontroller,代碼行數:18,代碼來源:SerialThreadService.java

示例15: ConnectedThread

import android.bluetooth.BluetoothSocket; //導入依賴的package包/類
public ConnectedThread(BluetoothSocket socket, String socketType) {
    Log.d(TAG, "create ConnectedThread: " + socketType);
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException | NullPointerException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
    mState = STATE_CONNECTED;
}
 
開發者ID:zeevy,項目名稱:grblcontroller,代碼行數:19,代碼來源:SerialThreadService.java


注:本文中的android.bluetooth.BluetoothSocket類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。