本文整理汇总了Java中android.bluetooth.BluetoothDevice.createBond方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothDevice.createBond方法的具体用法?Java BluetoothDevice.createBond怎么用?Java BluetoothDevice.createBond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothDevice
的用法示例。
在下文中一共展示了BluetoothDevice.createBond方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBondDiscoveredDevices
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
private void createBondDiscoveredDevices() {
Log.d(TAG, "createBondDiscoveredDevices");
if (mTargetDevices.size() <= 0) {
Log.d(TAG, "no new discovered device");
return;
}
for (BluetoothDevice device : mTargetDevices) {
Log.d(TAG, "discovered device:" + device.getName());
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
Log.d(TAG, "already bonded.");
} else {
Log.d(TAG, "try to createBond..");
boolean result = device.createBond();
Log.d(TAG, "device.createBond() result: " + result);
}
}
}
示例2: pair
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
* Performs the device pairing.
*
* @param device the device to pair with.
* @return true if the pairing was successful, false otherwise.
*/
public boolean pair(BluetoothDevice device) {
// Stops the discovery and then creates the pairing.
if (bluetooth.isDiscovering()) {
Log.d(TAG, "Bluetooth cancelling discovery.");
bluetooth.cancelDiscovery();
}
Log.d(TAG, "Bluetooth bonding with device: " + deviceToString(device));
boolean outcome = device.createBond();
Log.d(TAG, "Bounding outcome : " + outcome);
// If the outcome is true, we are bounding with this device.
if (outcome == true) {
this.boundingDevice = device;
}
return outcome;
}
示例3: onReceive
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BluetoothDevice.ACTION_FOUND)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.d(TAG, "New Bluetooth device found: " + device.getName() +
" (" + device.getAddress() + ")");
if ((device.getName() != null && device.getName().equals(HC05_NAME))
|| device.getAddress().equals(HC05_MAC)) {
mBluetoothAdapter.cancelDiscovery();
device.setPin(HC05_PIN);
device.createBond();
}
}
}
示例4: createBond
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private boolean createBond(final BluetoothDevice device) {
if (device.getBondState() == BluetoothDevice.BOND_BONDED)
return true;
boolean result;
mRequestCompleted = false;
sendLogBroadcast(LOG_LEVEL_VERBOSE, "Starting pairing...");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.getDevice().createBond()");
result = device.createBond();
} else {
result = createBondApi18(device);
}
// We have to wait until device is bounded
try {
synchronized (mLock) {
while (!mRequestCompleted && !mAborted)
mLock.wait();
}
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
return result;
}
示例5: createBond
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
* Pair with the specific device.
*/
public boolean createBond(BluetoothDevice device) {
boolean result = device.createBond();
Timber.d("Creating bond with: %s/%s/%b", device.getName(), device.getAddress(), result);
return result;
}