本文整理汇总了Java中android.bluetooth.BluetoothDevice.BOND_NONE属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothDevice.BOND_NONE属性的具体用法?Java BluetoothDevice.BOND_NONE怎么用?Java BluetoothDevice.BOND_NONE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.bluetooth.BluetoothDevice
的用法示例。
在下文中一共展示了BluetoothDevice.BOND_NONE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performBondStateChangeAction
private void performBondStateChangeAction(Intent intent) {
final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
final int prevState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
if (state == BluetoothDevice.BOND_BONDED && prevState == BluetoothDevice.BOND_BONDING) {
showToast(mContext.getString(R.string.device_paired));
connectToZephyrDevice();
} else if (state == BluetoothDevice.BOND_NONE) {
showToast(mContext.getString(R.string.device_pairing_failure));
}
}
示例2: onReceive
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// Discovery has found a device.
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object and its info from the Intent.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int bondState = device.getBondState();
String foundName = device.getName();
String foundAddress = device.getAddress(); // MAC address
Timber.d("Discovery has found a device: %d/%s/%s", bondState, foundName, foundAddress);
if (isSelectedDevice(foundAddress)) {
createBond(device);
} else {
Timber.d("Unknown device, skipping bond attempt.");
}
} else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
switch (state) {
case BluetoothDevice.BOND_NONE:
Timber.d("The remote device is not bonded.");
break;
case BluetoothDevice.BOND_BONDING:
Timber.d("Bonding is in progress with the remote device.");
break;
case BluetoothDevice.BOND_BONDED:
Timber.d("The remote device is bonded.");
break;
default:
Timber.d("Unknown remote device bonding state.");
break;
}
}
}
示例3: handleMessage
@Override
public void handleMessage(Message msg) {
if (msg.what == Comment.BOND) {
if ((int) msg.obj == BluetoothDevice.BOND_NONE) {
DialogUtil.CancelProgress();
ToastUtil.showShort(BluetoothManngerActivity.this, "取消配对成功");
finish();
}
}if (msg.what ==Comment.CONNECT){
ToastUtil.showShort(BluetoothManngerActivity.this,"连接成功!");
}if (msg.what==0){
ToastUtil.showShort(BluetoothManngerActivity.this, "传输成功!");
}if (msg.what==1){
ToastUtil.showShort(BluetoothManngerActivity.this, "传输失败!");
}if (msg.what==2){
ToastUtil.showShort(BluetoothManngerActivity.this, "连接失败!");
}
}
示例4: connectBound
/**
* 发起配对
*/
public static void connectBound() {
if (Comment.bluetoothDevice.getBondState() == BluetoothDevice.BOND_NONE) {
new Thread(new Runnable() {
@Override
public void run() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Comment.bluetoothDevice.createBond();
} else {
Method method = BluetoothDevice.class.getMethod("createBond");
method.invoke(Comment.bluetoothDevice);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
示例5: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
switch (bondState) {
case BluetoothDevice.BOND_NONE:
Log.d(TAG, "Bluetooth device not paired!");
break;
case BluetoothDevice.BOND_BONDING:
Log.d(TAG, "Bluetooth device pairing!");
break;
case BluetoothDevice.BOND_BONDED:
Log.d(TAG, "Bluetooth device paired!");
break;
}
}
}
示例6: onCharacteristicWrite
@Override
public void onCharacteristicWrite(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(mLogSession, "Data written to " + characteristic.getUuid() + ", value: " + ParserUtils.parse(characteristic.getValue()));
// The value has been written. Notify the manager and proceed with the initialization queue.
onCharacteristicWrite(gatt, characteristic);
nextRequest();
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onCharacteristicRead error " + status);
onError(ERROR_READ_CHARACTERISTIC, status);
}
}
示例7: refreshDeviceCache
/**
* Clears the device cache. After uploading new firmware the DFU target will have other services than before.
*
* @param gatt the GATT device to be refreshed
* @param force <code>true</code> to force the refresh
*/
private void refreshDeviceCache(final BluetoothGatt gatt, final boolean force) {
/*
* If the device is bonded this is up to the Service Changed characteristic to notify Android that the services has changed.
* There is no need for this trick in that case.
* If not bonded, the Android should not keep the services cached when the Service Changed characteristic is present in the target device database.
* However, due to the Android bug (still exists in Android 5.0.1), it is keeping them anyway and the only way to clear services is by using this hidden refresh method.
*/
if (force || gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.refresh()");
/*
* There is a refresh() method in BluetoothGatt class but for now it's hidden. We will call it using reflections.
*/
try {
final Method refresh = gatt.getClass().getMethod("refresh");
if (refresh != null) {
final boolean success = (Boolean) refresh.invoke(gatt);
logi("Refreshing result: " + success);
}
} catch (Exception e) {
loge("An exception occurred while refreshing device", e);
sendLogBroadcast(LOG_LEVEL_WARNING, "Refreshing failed");
}
}
}
示例8: onDevicePairingEnded
/**
* {@inheritDoc}
*/
@Override
public void onDevicePairingEnded() {
if (bluetooth.isPairingInProgress()) {
BluetoothDevice device = bluetooth.getBoundingDevice();
switch (bluetooth.getPairingDeviceStatus()) {
case BluetoothDevice.BOND_BONDING:
// Still pairing, do nothing.
break;
case BluetoothDevice.BOND_BONDED:
// Successfully paired.
listener.endLoadingWithDialog(false, device);
// Updates the icon for this element.
notifyDataSetChanged();
break;
case BluetoothDevice.BOND_NONE:
// Failed pairing.
listener.endLoadingWithDialog(true, device);
break;
}
}
}
示例9: connect
@Override
public void connect() {
if (!connected) {
if (serviceId == null) {
onError(ErrorCode.ServiceIdRequired);
return;
}
if (device.getBondState() != BluetoothDevice.BOND_NONE) {
deleteBondInformation();
if (device.getBondState() != BluetoothDevice.BOND_NONE) {
onError(ErrorCode.RemovePairing);
}
}
btGatt = device.connectGatt(app, false, btgCallback);
onStatus(StatusCode.Connecting);
// will be canceled if connection is successful or explicitly fails.
taskConnectTimeout = new TimerTask() {
@Override
public void run() {
onError(ErrorCode.Connect);
btGatt.disconnect();
}
};
timer.schedule(taskConnectTimeout, 10000);
}
}
示例10: foundDevice
public boolean foundDevice (BluetoothDevice device)
{
boolean resultIsNew = false;
if (device != null && device.getName() != null &&
(device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_HANDHELD_PC_PDA ||
device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_PALM_SIZE_PC_PDA ||
device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PHONE_SMART)) {
if (mPairedDevicesOnly && device.getBondState() == BluetoothDevice.BOND_NONE)
return false; //we can only support paired devices
if (!mFoundDevices.containsKey(device.getAddress())) {
mFoundDevices.put(device.getAddress(), device);
resultIsNew = true;
if (mNearbyListener != null) {
Neighbor neighbor = new Neighbor(device.getAddress(),device.getName(),Neighbor.TYPE_BLUETOOTH);
mNearbyListener.foundNeighbor(neighbor);
}
}
if (clientThreads.containsKey(device.getAddress()))
if (clientThreads.get(device.getAddress()).isAlive())
return false; //we have a running thread here people!
log("Found device: " + device.getName() + ":" + device.getAddress());
ClientThread clientThread = new ClientThread(device, mHandler, mPairedDevicesOnly);
clientThread.start();
clientThreads.put(device.getAddress(), clientThread);
}
return resultIsNew;
}
示例11: onReceive
@Override
public void onReceive(Context context, Intent intent) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (intent.getAction().equals(BluetoothDevice.ACTION_FOUND)) {
if((mType == TypeBluetooth.Client && !isConnected)
|| (mType == TypeBluetooth.Server && !mAdressListServerWaitingConnection.contains(device.getAddress()))){
EventBus.getDefault().post(device);
}
}
else if (intent.getAction().equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
{
//start it up again!
scanAllBluetoothDevice();
}
else if(intent.getAction().equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)){
//Log.e("", "===> ACTION_BOND_STATE_CHANGED");
int prevBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1);
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
if (prevBondState == BluetoothDevice.BOND_BONDING)
{
// check for both BONDED and NONE here because in some error cases the bonding fails and we need to fail gracefully.
if (bondState == BluetoothDevice.BOND_BONDED || bondState == BluetoothDevice.BOND_NONE )
{
//Log.e("", "===> BluetoothDevice.BOND_BONDED");
EventBus.getDefault().post(new BondedDevice());
}
}
}
}
示例12: ConnectClick
public void ConnectClick(View v) {
try {
//验证输入的密码
if (!etPassword.getText().toString().equals("") && etPassword.getText().toString().length() < 8) {
ToastUtil.showToast(this, R.string.add_device_wifi_check);
return;
}
if (type == 1) {
//开始计时
new Thread(new MyThread()).start();
ConnectWLAN();
return;
}
if (bluetoothXlight.getBondState() == BluetoothDevice.BOND_NONE) {
//利用反射方法调用BluetoothDevice.createBond(BluetoothDevice remoteDevice);
Log.d("XLight", "开始配对");
new Thread(new MyThread()).start();
ToastUtil.showLoading(this, null, getResources().getString(R.string.add_device_wifi_step1));
ClsUtils.pair(bluetoothXlight.getAddress(), "1234");
} else if (bluetoothXlight.getBondState() == BluetoothDevice.BOND_BONDED) {
ClsUtils.removeBond(bluetoothXlight.getClass(), bluetoothXlight);
ConnectClick(null);
}
} catch (Exception e) {
}
}
示例13: resolveBondingState
/**
* Resolve bonding state.
*
* @param bondState the bond state
* @return the string
*/
private static String resolveBondingState(final int bondState) {
switch (bondState) {
case BluetoothDevice.BOND_BONDED:
return "Paired";
case BluetoothDevice.BOND_BONDING:
return "Pairing";
case BluetoothDevice.BOND_NONE:
return "Unbonded";
default:
return "Unknown";
}
}
示例14: onCharacteristicRead
@Override
public final void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(mLogSession, "Read Response received from " + characteristic.getUuid() + ", value: " + ParserUtils.parse(characteristic));
if (isBatteryLevelCharacteristic(characteristic)) {
final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
mCallbacks.onBatteryValueReceived(batteryValue);
// The Battery Level value has been read. Let's try to enable Battery Level notifications.
// If the Battery Level characteristic does not have the NOTIFY property, proceed with the initialization queue.
if (!setBatteryNotifications(true))
nextRequest();
} else {
// The value has been read. Notify the manager and proceed with the initialization queue.
onCharacteristicRead(gatt, characteristic);
nextRequest();
}
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onCharacteristicRead error " + status);
onError(ERROR_READ_CHARACTERISTIC, status);
}
}
示例15: onDescriptorWrite
@Override
public final void onDescriptorWrite(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(mLogSession, "Data written to descr. " + descriptor.getUuid() + ", value: " + ParserUtils.parse(descriptor));
if (isServiceChangedCCCD(descriptor)) {
Logger.a(mLogSession, "Service Changed notifications enabled");
if (!readBatteryLevel())
nextRequest();
} else if (isBatteryLevelCCCD(descriptor)) {
final byte[] value = descriptor.getValue();
if (value != null && value.length > 0 && value[0] == 0x01) {
Logger.a(mLogSession, "Battery Level notifications enabled");
nextRequest();
} else
Logger.a(mLogSession, "Battery Level notifications disabled");
} else {
nextRequest();
}
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onDescriptorWrite error " + status);
onError(ERROR_WRITE_DESCRIPTOR, status);
}
}