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


Java BluetoothDevice.createInsecureRfcommSocketToServiceRecord方法代碼示例

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


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

示例1: ConnectThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的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

示例2: ConnectThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的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

示例3: ConnectThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的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

示例4: doInBackground

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... devices) //while the progress dialog is shown, the connection is done in background
{
    try
    {
        if (btSocket == null || !isBtConnected)
        {
            myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
            BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available
            btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
            BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
            btSocket.connect();//start connection
        }
    }
    catch (IOException e)
    {
        ConnectSuccess = false;//if the try failed, you can check the exception here
    }
    return null;
}
 
開發者ID:mahto56,項目名稱:Qeet-Remote,代碼行數:21,代碼來源:MainActivity.java

示例5: doInBackground

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... devices) //while the progress dialog is shown, the connection is done in background
{
    try
    {
        if (btSocket == null || !isBtConnected)
        {
            myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
            BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available
            btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
            BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
            btSocket.connect();//start connection
            mmInputStream = btSocket.getInputStream();
        }
    }
    catch (IOException e)
    {
        ConnectSuccess = false;//if the try failed, you can check the exception here
    }
    return null;
}
 
開發者ID:NullPointersInc,項目名稱:Bella-Android,代碼行數:22,代碼來源:MainActivity.java

示例6: ConnectThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的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

示例7: ClientThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
public ClientThread(BluetoothDevice device, Handler handler, boolean secure) {
    BluetoothSocket tempSocket = null;
    this.handler = handler;
    this.secure = secure;
    this.device = device;

    try {
        if (secure)
            tempSocket = device.createRfcommSocketToServiceRecord(UUID.fromString(Constants.UUID_STRING));
        else
            tempSocket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(Constants.UUID_STRING));

    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
    this.socket = tempSocket;
}
 
開發者ID:n8fr8,項目名稱:LittleBitLouder,代碼行數:18,代碼來源:ClientThread.java

示例8: ConnectionThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
/**
 * Creates the thread
 * @param playerToConnect player to connect to
 */
public ConnectionThread(Player playerToConnect) {
    //gets the device to connect to (the player's device)
    BluetoothDevice deviceToConnect = BluetoothServices.getmBluetoothAdapter().getRemoteDevice(playerToConnect.getMAC());
    System.out.println("device to connect to");
    System.out.println(deviceToConnect.getAddress());
    System.out.println(deviceToConnect.getName());
    System.out.println(deviceToConnect.toString());
    System.out.println("device to connect to");
    // Use a temporary object that is later assigned to mmSocket,
    // because mmSocket is final
    BluetoothSocket tmp = null;

    // Get a BluetoothSocket to connect with the given BluetoothDevice (that is a player)
    try {
        // MY_UUID is the app's UUID string, also used by the reception part of the code
        // creates and insecure RF socket
        tmp = deviceToConnect.createInsecureRfcommSocketToServiceRecord(MainActivity.uuid);
        System.out.println("Socket found!");

    } catch (IOException e) { }
    mmSocket = tmp;
}
 
開發者ID:mcr222,項目名稱:pass_the_bomb,代碼行數:27,代碼來源:ConnectionThread.java

示例9: ConnectThread

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

    // Get a BluetoothSocket for a connection with the
    // given BluetoothDevice
    try {
        tmp = device.createInsecureRfcommSocketToServiceRecord(
                    MY_UUID_INSECURE);

    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
    }
    mmSocket = tmp;
    mState = STATE_CONNECTING;
}
 
開發者ID:alexmerz,項目名稱:dab-iot,代碼行數:18,代碼來源:BluetoothChatService.java

示例10: doInBackground

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... params) {
    try{
        if (btSocket == null || !isBtConnected){
            myBluetooth = BluetoothAdapter.getDefaultAdapter(); //get the mobiles bluetooth
            BluetoothDevice btd = myBluetooth.getRemoteDevice(address);
            btSocket = btd.createInsecureRfcommSocketToServiceRecord(myUUID);
            BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
            btSocket.connect();
        }
    }catch(IOException e){
        ConnectionSuccess = false;
    }
    return null;
}
 
開發者ID:chooka888,項目名稱:BluetoothDuck,代碼行數:16,代碼來源:BTTerminal.java

示例11: ConnectThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的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

示例12: BluetoothClassicClient

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
public BluetoothClassicClient(BluetoothDevice device, UUID uuid) {
    macAddress = device.getAddress();
    try {
        socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
    } catch (IOException connectException) {
        Log.e(TAG, "Failed to set up a Bluetooth Classic connection as a client", connectException);
    }
}
 
開發者ID:aarmea,項目名稱:noise,代碼行數:9,代碼來源:BluetoothSyncService.java

示例13: ConnectThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
/**
 * Instantiates a new Connect thread.
 *
 * @param device the device
 */
public ConnectThread( BluetoothDevice device )
{
	mmDevice = device;

	BluetoothSocket tmp = null;
	if(mmDevice.getBluetoothClass() == null)
		mProtocolVer = 1;
	else if(mmDevice.getBluetoothClass().toString().equals( "51c") || mmDevice.getBluetoothClass().toString().equals( "2510"))
		mProtocolVer = 2;
	else
		mProtocolVer = 1;

	try
	{
		if(mProtocolVer == 2 && Build.VERSION.SDK_INT >= 19)
			tmp = device.createRfcommSocketToServiceRecord( NeoOne_UUID );
		else
			tmp = device.createInsecureRfcommSocketToServiceRecord( NeoOne_UUID );


	}
	catch ( Exception e )
	{
		NLog.e( "[BTAdt/ConnectThread] Socket Type : create() failed", e );
	}

	mmSocket = tmp;
}
 
開發者ID:NeoSmartpen,項目名稱:AndroidSDK2.0,代碼行數:34,代碼來源:BTAdt.java

示例14: doInBackground

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... params) {

    try {
        if (btSocket == null || !isBtConnected) {

            bluetoothHandler.obtainMessage(BluetoothStates.BLUETOOTH_CONNECTING).sendToTarget();

            //connects to the device's address and checks if it's available
            BluetoothDevice bluetoothDevice = myBluetoothAdapter.getRemoteDevice(devicesAddress);

            //create a RFCOMM (SPP) connection
            btSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(myUUID);

            BluetoothAdapter.getDefaultAdapter().cancelDiscovery();

            //start connection
            btSocket.connect();
        }

    } catch (IOException e) {
        //if the try failed, you can check the exception here
        connectSuccess = false;
    }

    return null;
}
 
開發者ID:Ahmed-Abdelmeged,項目名稱:Android-BluetoothMCLibrary,代碼行數:28,代碼來源:BluetoothMC.java

示例15: BluetoothServiceThread

import android.bluetooth.BluetoothDevice; //導入方法依賴的package包/類
public BluetoothServiceThread(BluetoothService bluetoothService, BluetoothDevice bluetoothDevice) {
    this.bluetoothService = bluetoothService;

    BluetoothSocket bluetoothSocket = null;
    try {
        bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(bluetoothService.getSppUuid());
    } catch (Throwable e) {
        Log.e(TAG, "could not create socket", e);
    }
    this.bluetoothSocket = bluetoothSocket;
}
 
開發者ID:journeyapps,項目名稱:journey-android-bluetooth-scale,代碼行數:12,代碼來源:BluetoothServiceThread.java


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