本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}