本文整理汇总了Java中android.bluetooth.BluetoothGattCallback类的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGattCallback类的具体用法?Java BluetoothGattCallback怎么用?Java BluetoothGattCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothGattCallback类属于android.bluetooth包,在下文中一共展示了BluetoothGattCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleDescriptorReadCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 读描述符
* @param bleCallback
*/
private void handleDescriptorReadCallback(final BleDescriptorCallback bleCallback) {
if (bleCallback != null) {
listenAndTimer(bleCallback, MSG_READ_DES, new BluetoothGattCallback() {
AtomicBoolean msgRemoved = new AtomicBoolean(false);
@Override
public void onDescriptorRead(BluetoothGatt gatt,
BluetoothGattDescriptor descriptor, int status) {
if (!msgRemoved.getAndSet(true)) {
handler.removeMessages(MSG_READ_DES, this);
}
if (status == BluetoothGatt.GATT_SUCCESS) {
bleCallback.onSuccess(descriptor);
} else {
bleCallback.onFailure(new GattException(status));
}
}
});
}
}
示例2: execute
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void execute(BluetoothGattCallback callback) {
NeatleLogger.d("Execute " + callback);
boolean wasIdle;
synchronized (lock) {
wasIdle = currentCallback == DO_NOTHING_CALLBACK;
if (currentCallback == callback || queue.contains(callback)) {
NeatleLogger.d("Restarting " + callback);
} else {
NeatleLogger.d("Queueing up " + callback);
queue.add(callback);
}
}
if (wasIdle && areServicesDiscovered()) {
resume();
} else {
connect();
}
}
示例3: executeFinished
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void executeFinished(BluetoothGattCallback callback) {
synchronized (lock) {
if (callback == currentCallback) {
this.currentCallback = DO_NOTHING_CALLBACK;
NeatleLogger.d("Finished " + callback);
handler.post(new Runnable() {
@Override
public void run() {
resume();
}
});
} else {
this.queue.remove(callback);
NeatleLogger.d("Removed from queue " + callback);
}
}
}
示例4: onCharacteristicRead
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
NeatleLogger.d("createCharacteristicRead");
BluetoothGattCallback target;
synchronized (lock) {
target = currentCallback;
}
target.onCharacteristicRead(gatt, characteristic, status);
}
示例5: onCharacteristicChanged
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
BluetoothGattCallback target;
synchronized (lock) {
target = currentCallback;
}
target.onCharacteristicChanged(gatt, characteristic);
notifyCharacteristicChange(CommandResult.createCharacteristicChanged(characteristic));
}
示例6: onConnectionStateChange
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 连接状态改变回调
* 系统自带API
* @param gatt
* @param status
* @param newState
*/
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (BleLog.isPrint) {
BleLog.i(TAG, "onConnectionStateChange status: " + status
+ " ,newState: " + newState + " ,thread: " + Thread.currentThread().getId());
}
if (newState == BluetoothGatt.STATE_CONNECTED) {
connectionState = STATE_CONNECTED;
// 连接成功
onConnectSuccess(gatt, status);
} else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
connectionState = STATE_DISCONNECTED;
// 连接失败
onConnectFailure(new ConnectException(gatt, status));
} else if (newState == BluetoothGatt.STATE_CONNECTING) {
connectionState = STATE_CONNECTING;
}
// 遍历回调回所有传进了的回调, 给子类处理
for (BluetoothGattCallback call : callbackList) {
call.onConnectionStateChange(gatt, status, newState);
}
}
示例7: handleCharacteristicWriteCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 处理向特征码写入数据的回调
* @param bleCallback
*/
private void handleCharacteristicWriteCallback(final BleCharactCallback bleCallback) {
if (bleCallback != null) {
// 添加连接回调到LiteBluetooth的回调集合中
listenAndTimer(bleCallback, MSG_WRIATE_CHA, new BluetoothGattCallback() {
@Override
public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
handler.removeMessages(MSG_WRIATE_CHA, this);
if (status == BluetoothGatt.GATT_SUCCESS) {
bleCallback.onSuccess(characteristic);
} else {
bleCallback.onFailure(new GattException(status));
}
}
});
}
}
示例8: handleDescriptorWriteCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 写描述符
* @param bleCallback
*/
private void handleDescriptorWriteCallback(final BleDescriptorCallback bleCallback) {
if (bleCallback != null) {
listenAndTimer(bleCallback, MSG_WRIATE_DES, new BluetoothGattCallback() {
@Override
public void onDescriptorWrite(BluetoothGatt gatt,
BluetoothGattDescriptor descriptor, int status) {
handler.removeMessages(MSG_WRIATE_DES, this);
if (status == BluetoothGatt.GATT_SUCCESS) {
bleCallback.onSuccess(descriptor);
} else {
bleCallback.onFailure(new GattException(status));
}
}
});
}
}
示例9: handleCharacteristicReadCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 读特征码
* @param bleCallback
*/
private void handleCharacteristicReadCallback(final BleCharactCallback bleCallback) {
if (bleCallback != null) {
listenAndTimer(bleCallback, MSG_READ_CHA, new BluetoothGattCallback() {
AtomicBoolean msgRemoved = new AtomicBoolean(false);
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
// 将原子设置为给定值并返回旧值
if (!msgRemoved.getAndSet(true)) {
// 只能进来执行一次
handler.removeMessages(MSG_READ_CHA, this);
}
if (status == BluetoothGatt.GATT_SUCCESS) {
bleCallback.onSuccess(characteristic);
} else {
bleCallback.onFailure(new GattException(status));
}
}
});
}
}
示例10: handleRSSIReadCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 读取RSSI, 回调返回
* @param bleCallback
*/
private void handleRSSIReadCallback(final BleRssiCallback bleCallback) {
if (bleCallback != null) {
listenAndTimer(bleCallback, MSG_READ_RSSI, new BluetoothGattCallback() {
@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
handler.removeMessages(MSG_READ_RSSI, this);
if (status == BluetoothGatt.GATT_SUCCESS) {
bleCallback.onSuccess(rssi);
} else {
bleCallback.onFailure(new GattException(status));
}
}
});
}
}
示例11: handleCharacteristicNotificationCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 读取特征码刷新数据
* @param bleCallback
*/
private void handleCharacteristicNotificationCallback(final BleCharactCallback bleCallback) {
if (bleCallback != null) {
listenAndTimer(bleCallback, MSG_NOTIY_CHA, new BluetoothGattCallback() {
AtomicBoolean msgRemoved = new AtomicBoolean(false);
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
if (!msgRemoved.getAndSet(true)) {
handler.removeMessages(MSG_NOTIY_CHA, this);
}
bleCallback.onSuccess(characteristic);
}
});
}
}
示例12: handleDescriptorNotificationCallback
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
/**
* 读取描述符刷新数据
* @param bleCallback
*/
private void handleDescriptorNotificationCallback(final BleDescriptorCallback bleCallback) {
if (bleCallback != null) {
listenAndTimer(bleCallback, MSG_NOTIY_DES, new BluetoothGattCallback() {
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
handler.removeMessages(MSG_NOTIY_DES, this);
if (status == BluetoothGatt.GATT_SUCCESS) {
bleCallback.onSuccess(descriptor);
} else {
bleCallback.onFailure(new GattException(status));
}
}
});
}
}
示例13: connect
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
@Override
public BluetoothGatt connect(P_NativeDeviceLayer device, Context context, boolean useAutoConnect, BluetoothGattCallback callback) {
m_gattIsNull = false;
m_explicitDisconnect = false;
m_device.getManager().getPostManager().postToUpdateThreadDelayed(new Runnable()
{
@Override public void run()
{
if (!m_explicitDisconnect)
{
setToConnecting();
}
}
}, 100);
m_device.getManager().getPostManager().postToUpdateThreadDelayed(new Runnable()
{
@Override public void run()
{
if (!m_explicitDisconnect)
{
setToConnected();
}
}
}, 250);
return device.connect(context, useAutoConnect, callback);
}
示例14: resume
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
private void resume() {
BluetoothGattCallback target;
BluetoothGatt targetGatt;
boolean doResume;
synchronized (lock) {
if (currentCallback == DO_NOTHING_CALLBACK) {
BluetoothGattCallback newCallback = queue.poll();
if (newCallback == null) {
if (changeListeners.isEmpty()) {
disconnectOnIdle();
}
return;
}
currentCallback = newCallback;
}
target = currentCallback;
doResume = areServicesDiscovered();
targetGatt = this.gatt;
}
if (doResume) {
NeatleLogger.i("Resuming with " + target);
currentCallback.onServicesDiscovered(targetGatt, BluetoothGatt.GATT_SUCCESS);
} else {
NeatleLogger.i("Will resume after services are discovered with " + target);
connect();
}
}
示例15: connectionFailed
import android.bluetooth.BluetoothGattCallback; //导入依赖的package包/类
private void connectionFailed(int status) {
BluetoothGattCallback current;
int oldState;
int newState;
LinkedList<BluetoothGattCallback> queueCopy;
synchronized (lock) {
oldState = state;
state = BluetoothGatt.STATE_DISCONNECTED;
newState = state;
serviceDiscovered = false;
current = currentCallback;
queueCopy = new LinkedList<>(queue);
}
NeatleLogger.i("Connection attempt failed. Notifying all pending operations");
current.onConnectionStateChange(this.gatt, status, BluetoothGatt.STATE_DISCONNECTED);
for (BluetoothGattCallback cb : queueCopy) {
cb.onConnectionStateChange(gatt, status, BluetoothGatt.STATE_DISCONNECTED);
}
synchronized (lock) {
this.gatt = null;
}
notifyConnectionStateChange(oldState, newState);
}