use of android.bluetooth.BluetoothGattService in project physical-web by google.
the class FatBeaconBroadcastService method initGattServer.
private void initGattServer() {
mGattServer = mBluetoothManager.openGattServer(this, mGattServerCallback);
BluetoothGattService service = new BluetoothGattService(UUID.fromString(SERVICE_UUID), BluetoothGattService.SERVICE_TYPE_PRIMARY);
BluetoothGattCharacteristic webpage = new BluetoothGattCharacteristic(CHARACTERISTIC_WEBPAGE_UUID, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ);
service.addCharacteristic(webpage);
mGattServer.addService(service);
}
use of android.bluetooth.BluetoothGattService in project Gadgetbridge by Freeyourgadget.
the class PebbleGATTServer method initialize.
boolean initialize() {
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothGattServer = bluetoothManager.openGattServer(mContext, this);
if (mBluetoothGattServer == null) {
return false;
}
BluetoothGattService pebbleGATTService = new BluetoothGattService(SERVER_SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY);
pebbleGATTService.addCharacteristic(new BluetoothGattCharacteristic(READ_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ));
writeCharacteristics = new BluetoothGattCharacteristic(WRITE_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_WRITE);
writeCharacteristics.addDescriptor(new BluetoothGattDescriptor(CHARACTERISTICS_CONFIGURATION_DESCRIPTOR, BluetoothGattDescriptor.PERMISSION_WRITE));
pebbleGATTService.addCharacteristic(writeCharacteristics);
mBluetoothGattServer.addService(pebbleGATTService);
return true;
}
use of android.bluetooth.BluetoothGattService in project Gadgetbridge by Freeyourgadget.
the class AbstractBTLEDeviceSupport method gattServicesDiscovered.
private void gattServicesDiscovered(List<BluetoothGattService> discoveredGattServices) {
if (discoveredGattServices == null) {
logger.warn("No gatt services discovered: null!");
return;
}
Set<UUID> supportedServices = getSupportedServices();
Map<UUID, BluetoothGattCharacteristic> newCharacteristics = new HashMap<>();
for (BluetoothGattService service : discoveredGattServices) {
if (supportedServices.contains(service.getUuid())) {
logger.debug("discovered supported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid());
List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
if (characteristics == null || characteristics.isEmpty()) {
logger.warn("Supported LE service " + service.getUuid() + "did not return any characteristics");
continue;
}
HashMap<UUID, BluetoothGattCharacteristic> intmAvailableCharacteristics = new HashMap<>(characteristics.size());
for (BluetoothGattCharacteristic characteristic : characteristics) {
intmAvailableCharacteristics.put(characteristic.getUuid(), characteristic);
logger.info(" characteristic: " + BleNamesResolver.resolveCharacteristicName(characteristic.getUuid().toString()) + ": " + characteristic.getUuid());
}
newCharacteristics.putAll(intmAvailableCharacteristics);
synchronized (characteristicsMonitor) {
mAvailableCharacteristics = newCharacteristics;
}
} else {
logger.debug("discovered unsupported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid());
}
}
}
use of android.bluetooth.BluetoothGattService in project BleLiteLib4android by afunx.
the class MainActivity method tapMe.
private void tapMe() {
Log.i(TAG, "tapMe()");
final String bleAddr = "24:0A:C4:00:02:BC";
final UUID UUID_WIFI_SERVICE = UUID.fromString("0000ffff-0000-1000-8000-00805f9b34fb");
final UUID UUID_CONFIGURE_CHARACTERISTIC = UUID.fromString("0000ff01-0000-1000-8000-00805f9b34fb");
final Context context = MainActivity.this;
final BleGattClientProxy proxy = mProxy;
new Thread() {
@Override
public void run() {
int count = 0;
while (!mIsStop) {
Log.e(TAG, "connect and close count: " + (++count));
proxy.connect(bleAddr, 20000);
BluetoothGattService gattService = proxy.discoverService(UUID_WIFI_SERVICE, 5000);
proxy.requestMtu(64, 2000);
if (gattService != null) {
BluetoothGattCharacteristic characteristic = proxy.discoverCharacteristic(gattService, UUID_CONFIGURE_CHARACTERISTIC);
if (characteristic != null) {
proxy.writeCharacteristic(characteristic, "ssid:wifi-11".getBytes(), 5000);
byte[] msgRead = proxy.readCharacteristic(characteristic, 5000);
System.out.println("BH msgRead: " + Arrays.toString(msgRead));
BleGattClientProxy.OnCharacteristicNotificationListener listener = new BleGattClientProxy.OnCharacteristicNotificationListener() {
@Override
public void onCharacteristicNotification(byte[] msg) {
System.out.println("BH ********************onCharacteristicNotification() msg: " + Arrays.toString(msg));
}
};
proxy.registerCharacteristicNotification(characteristic, listener);
proxy.writeCharacteristic(characteristic, "passwd:sumof1+1=2".getBytes(), 5000);
proxy.writeCharacteristic(characteristic, "confirm:".getBytes(), 5000);
proxy.unregisterCharacteristicNotification(characteristic.getUuid());
System.out.println("BH ********************Sleep 20 seconds********************");
try {
Thread.sleep(20 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mIsStop = true;
}
}
proxy.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
use of android.bluetooth.BluetoothGattService in project BleSensorTag by StevenRudenko.
the class BleServicesAdapter method getGroupView.
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
final GroupViewHolder holder;
if (convertView == null) {
holder = new GroupViewHolder();
convertView = inflater.inflate(R.layout.li_service, parent, false);
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.uuid = (TextView) convertView.findViewById(R.id.uuid);
convertView.setTag(holder);
} else {
holder = (GroupViewHolder) convertView.getTag();
}
final BluetoothGattService item = getGroup(groupPosition);
final String serviceName;
final String uuid;
if (item == null) {
serviceName = "Unknown";
uuid = null;
} else if (def == null) {
serviceName = "Unknown";
uuid = item.getUuid().toString();
} else {
uuid = item.getUuid().toString();
final Sensor sensor = def.getSensor(uuid);
if (sensor != null) {
serviceName = sensor.getName();
} else {
serviceName = "Unknown";
}
}
holder.name.setText(serviceName);
holder.uuid.setText(uuid);
return convertView;
}
Aggregations