本文整理匯總了Java中android.bluetooth.BluetoothGatt.getDevice方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGatt.getDevice方法的具體用法?Java BluetoothGatt.getDevice怎麽用?Java BluetoothGatt.getDevice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGatt
的用法示例。
在下文中一共展示了BluetoothGatt.getDevice方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ensureServiceChangedEnabled
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
* When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic.
* In case one of the requirements is not fulfilled this method returns <code>false</code>.
*
* @param gatt the gatt device with services discovered
* @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have
* the Service Changed characteristic or this characteristic does not have the CCCD.
*/
private boolean ensureServiceChangedEnabled(final BluetoothGatt gatt) {
if (gatt == null)
return false;
// The Service Changed indications have sense only on bonded devices
final BluetoothDevice device = gatt.getDevice();
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
return false;
final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE);
if (gaService == null)
return false;
final BluetoothGattCharacteristic scCharacteristic = gaService.getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC);
if (scCharacteristic == null)
return false;
return enableIndications(scCharacteristic);
}
示例2: ensureServiceChangedEnabled
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
* When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic.
* In case one of the requirements is not fulfilled this method returns <code>false</code>.
*
* @param gatt the gatt device with services discovered
* @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have
* the Service Changed characteristic or this characteristic does not have the CCCD.
*/
private boolean ensureServiceChangedEnabled(final BluetoothGatt gatt) {
if (gatt == null)
return false;
// The Service Changed indications have sense only on bonded devices
final BluetoothDevice device = gatt.getDevice();
if (device.getBondState() != BluetoothDevice.BOND_BONDED)
return false;
final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE);
if (gaService == null)
return false;
final BluetoothGattCharacteristic scCharacteristic = gaService.getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC);
if (scCharacteristic == null)
return false;
Logger.i(mLogSession, "Service Changed characteristic found on a bonded device");
return enableIndications(scCharacteristic);
}
示例3: onServicesDiscovered
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.i(TAG, "onServicesDiscovered called...");
BluetoothDevice device = gatt.getDevice();
int discoveredServices = gatt.getServices().size();
if(discoveredServices == 0 && isConnected(device)) {
Log.i(TAG, "Re-discovering services. No previous services and is connected");
gatt.discoverServices();
return;
}
broadcastUpdate(ACTION_GATT_CLIENT_SERVICES_DISCOVERED);
}