List of usage examples for android.bluetooth BluetoothGatt GATT_SUCCESS
int GATT_SUCCESS
To view the source code for android.bluetooth BluetoothGatt GATT_SUCCESS.
Click Source Link
From source file:net.emilymaier.movebot.HeartFragment.java
@Override @SuppressWarnings("deprecation") public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { Log.d("HeartFragment", "Bluetooth LE device found"); BluetoothGatt bluetoothGatt = device.connectGatt(act, false, new BluetoothGattCallback() { @Override// www.j ava 2 s . com public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { Log.d("HeartFragment", "Connected to LE device"); gatt.discoverServices(); } } @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { BluetoothGattCharacteristic characteristic = null; for (BluetoothGattService service : gatt.getServices()) { characteristic = service .getCharacteristic(UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb")); if (characteristic != null) { break; } } if (characteristic != null) { Log.d("HeartFragment", "Found device with HRM characteristic"); HeartDevice device = new HeartDevice(); device.bluetoothGatt = gatt; device.characteristic = characteristic; for (HeartDevice testDevice : heartDevices) { if (testDevice.bluetoothGatt.getDevice().getAddress() .equals(device.bluetoothGatt.getDevice().getAddress())) { heartDevices.remove(testDevice); } } heartDevices.add(device); } else { Log.d("HeartFragment", "Device does not have HRM characteristic"); gatt.disconnect(); gatt.close(); } } else { Log.w("HeartFragment", "Failed to discover device services"); gatt.disconnect(); gatt.close(); } } @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; } else { format = BluetoothGattCharacteristic.FORMAT_UINT8; } final int heartRate = characteristic.getIntValue(format, 1); act.runOnUiThread(new Runnable() { @Override public void run() { act.updateHeart(heartRate); } }); } }); }
From source file:com.megster.cordova.ble.central.Peripheral.java
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicRead(gatt, characteristic, status); LOG.d(TAG, "onCharacteristicRead " + characteristic); if (readCallback != null) { if (status == BluetoothGatt.GATT_SUCCESS) { readCallback.success(characteristic.getValue()); } else {//w w w. ja v a 2 s . c o m readCallback.error("Error reading " + characteristic.getUuid() + " status=" + status); } readCallback = null; } commandCompleted(); }
From source file:com.karma.konnect.BeaconConfigFragment.java
public void onBeaconConfigReadUrlComplete(ConfigUriBeacon uriBeacon, int status) { if (status != BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onUriBeaconRead - error " + status); return;/*from www. jav a 2s. c o m*/ } if (uriBeacon == null) { Toast.makeText(getActivity(), R.string.config_url_read_error, Toast.LENGTH_SHORT).show(); setEditCardUrl(""); return; } final String url = uriBeacon.getUriString(); Log.d(TAG, "onReadUrlComplete" + " url: " + url); if (!isShortUrl(url)) { setEditCardUrl(url); } // Create the callback object to set the url PwsClient.ResolveScanCallback resolveScanCallback = new PwsClient.ResolveScanCallback() { @Override public void onUrlMetadataReceived(PwoMetadata pwoMetadata) { setEditCardUrl(pwoMetadata.urlMetadata.siteUrl); } @Override public void onUrlMetadataAbsent(PwoMetadata pwoMetadata) { setEditCardUrl(url); } }; PwoMetadata pwoMetadata = new PwoMetadata(url, 0); PwsClient.getInstance(getActivity()).findUrlMetadata(pwoMetadata, resolveScanCallback, TAG); }
From source file:com.megster.cordova.ble.central.Peripheral.java
@Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicWrite(gatt, characteristic, status); LOG.d(TAG, "onCharacteristicWrite " + characteristic); if (writeCallback != null) { if (status == BluetoothGatt.GATT_SUCCESS) { writeCallback.success();/* w w w. j av a 2 s . c o m*/ } else { writeCallback.error(status); } writeCallback = null; } commandCompleted(); }
From source file:gsoc.google.com.byop.utils.PW.BeaconConfigFragment.java
public void onBeaconConfigReadUrlComplete(ConfigUriBeacon uriBeacon, int status) { if (status != BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onUriBeaconRead - error " + status); return;// ww w.java2s . c o m } if (uriBeacon == null) { Toast.makeText(getActivity(), R.string.config_url_read_error, Toast.LENGTH_SHORT).show(); setEditCardUrl(""); return; } final String url = uriBeacon.getUriString(); Log.d(TAG, "onReadUrlComplete" + " url: " + url); if (!isShortUrl(url)) { setEditCardUrl(url); return; } // Populate the field with a URL. new PwsClient().resolve(Arrays.asList(url), new PwsResultCallback() { public void runSetEditCardUrlOnUiThread(final String url) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { setEditCardUrl(url); } }); } @Override public void onPwsResult(PwsResult pwsResult) { runSetEditCardUrlOnUiThread(pwsResult.getSiteUrl()); } @Override public void onPwsResultAbsent(String url) { runSetEditCardUrlOnUiThread(url); } }); }
From source file:com.karma.konnect.BeaconConfigFragment.java
public void onBeaconConfigWriteUrlComplete(final int status) { // Detach this fragment from its activity getFragmentManager().popBackStack(); // Show a toast to the user to let them know if the Url was written or error occurred. int msgId = (status == BluetoothGatt.GATT_SUCCESS) ? R.string.config_url_saved : R.string.config_url_error; Toast.makeText(getActivity(), msgId, Toast.LENGTH_SHORT).show(); }
From source file:com.junkchen.blelib.sample.BleScanActivity.java
private void setBleServiceListener() { mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { @Override//w ww . j ava2s . c om public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServiceList = gatt.getServices(); characteristicList = new ArrayList<>(); serviceList.clear(); for (BluetoothGattService service : gattServiceList) { String serviceUuid = service.getUuid().toString(); serviceList.add(MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); Log.i(TAG, MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); String[] charArra = new String[characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { String charUuid = characteristics.get(i).getUuid().toString(); charArra[i] = MyGattAttributes.lookup(charUuid, "Unknown") + "\n" + charUuid; } characteristicList.add(charArra); } mHandler.sendEmptyMessage(SERVICE_SHOW); } } }); // //Ble?? // mBleService.setOnLeScanListener(new BleService.OnLeScanListener() { // @Override // public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { // //???Ble????? // } // }); // //Ble // mBleService.setOnConnectListener(new BleService.OnConnectListener() { // @Override // public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { // if (newState == BluetoothProfile.STATE_DISCONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTING) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_DISCONNECTING) { // //Ble // } // } // }); // //Ble?? // mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { // @Override // public void onServicesDiscovered(BluetoothGatt gatt, int status) { // // } // }); // //Ble? // mBleService.setOnDataAvailableListener(new BleService.OnDataAvailableListener() { // @Override // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // //??? // } // // @Override // public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { // //?? // } // @Override // public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { // // } // }); mBleService.setOnReadRemoteRssiListener(new BleService.OnReadRemoteRssiListener() { @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { Log.i(TAG, "onReadRemoteRssi: rssi = " + rssi); } }); }
From source file:com.beestar.ble.ble.ui.BleScanActivity.java
private void setBleServiceListener() { mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { @Override//from w w w .ja v a2 s . com public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServiceList = gatt.getServices(); serviceList.clear(); for (BluetoothGattService service : gattServiceList) { String serviceUuid = service.getUuid().toString(); serviceList.add(MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); Log.i(TAG, MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); String[] charArra = new String[characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { String charUuid = characteristics.get(i).getUuid().toString(); charArra[i] = MyGattAttributes.lookup(charUuid, "Unknown") + "\n" + charUuid; } characteristicList.add(charArra); } mHandler.sendEmptyMessage(SERVICE_SHOW); } } }); // //Ble?? // mBleService.setOnLeScanListener(new BleService.OnLeScanListener() { // @Override // public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { // //???Ble????? // } // }); // //Ble // mBleService.setOnConnectListener(new BleService.OnConnectListener() { // @Override // public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { // if (newState == BluetoothProfile.STATE_DISCONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTING) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_DISCONNECTING) { // //Ble // } // } // }); // //Ble?? // mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { // @Override // public void onServicesDiscovered(BluetoothGatt gatt, int status) { // // } // }); // //Ble? // mBleService.setOnDataAvailableListener(new BleService.OnDataAvailableListener() { // @Override // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // //??? // } // // @Override // public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { // //?? // } // @Override // public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { // // } // }); mBleService.setOnReadRemoteRssiListener(new BleService.OnReadRemoteRssiListener() { @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { Log.i(TAG, "onReadRemoteRssi: rssi = " + rssi); } }); }
From source file:com.mooshim.mooshimeter.main.ScanActivity.java
private void toggleConnectionState(final Button bv, final MooshimeterDevice m) { bv.setEnabled(false);/*from w ww . ja v a 2 s.c om*/ bv.setAlpha((float) 0.5); Thread t = new Thread(new Runnable() { @Override public void run() { if (m.mConnectionState == BluetoothProfile.STATE_CONNECTED || m.mConnectionState == BluetoothProfile.STATE_CONNECTING) { m.disconnect(); } else { int rval; setStatus("Connecting..."); rval = m.connect(); if (BluetoothGatt.GATT_SUCCESS != rval) { setStatus(String.format("Connection failed. Status: %d", rval)); return; } setStatus("Discovering Services..."); rval = m.discover(); if (BluetoothGatt.GATT_SUCCESS != rval) { setStatus(String.format("Discovery failed. Status: %d", rval)); return; } setStatus("Connected!"); startSingleMeterActivity(m); } runOnUiThread(new Runnable() { @Override public void run() { bv.setEnabled(true); bv.setAlpha((float) 1.0); int bgid = m.mConnectionState == BluetoothProfile.STATE_CONNECTED ? R.drawable.connected : R.drawable.disconnected; bv.setBackground(getResources().getDrawable(bgid)); } }); } }); t.start(); }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void writeValueManage(BluetoothGatt gatt, int status) { String deviceAddress = getDeviceAddress(gatt); if (writeValueCC.get(deviceAddress) != null) { if (status == BluetoothGatt.GATT_SUCCESS) { Tools.sendSuccessMsg(writeValueCC.get(deviceAddress)); writeValueCC.remove(deviceAddress); } else {//from w ww . j av a 2s .c o m Tools.sendErrorMsg(writeValueCC.get(deviceAddress)); writeValueCC.remove(deviceAddress); } } }