RxAndroidBle | Android Bluetooth Low Energy Library with RxJava2 | Reactive Programming library
kandi X-RAY | RxAndroidBle Summary
kandi X-RAY | RxAndroidBle Summary
RxAndroidBle is a powerful painkiller for Android's Bluetooth Low Energy headaches. It is backed by RxJava, implementing complicated APIs as handy reactive observables. The library does for you:. For support head to StackOverflow #rxandroidble. Read the official announcement at Polidea Blog.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Construct a byte array from a scan record
- Adds a field to the advertisement packet
- Checks if the specified UUID is a 32 bit UUID
- Format UUID to byte array
- Helper method to actually write the queue
- Creates and returns a function which returns a function which returns a function which can be invoked when the Observable fails
- Creates a function which returns a function that when the buffer is not empty
- Creates an scan callback that can be used for scan results
- Converts a scan error code to a BleScanException
- Performs the actual disconnect operation
- Sets the custom logger implementation
- Initializes the BluetoothGatt characteristic
- Gets the string value of the specified byte array
- Add a scan result
- Initializes the BeaconView
- Set up the device to be created
- Get the current location provider status
- Runs the given operation on the queue
- Returns a scan setup for the given scan settings
- Performs a scan
- Returns the integer value from the given byte array
- Writes this field to Parcelable
- Asynchronously scans a pending intent
- Create a new long - write operation builder
- Initializes the device
- Handle notification event
RxAndroidBle Key Features
RxAndroidBle Examples and Code Snippets
import 'package:http/http.dart' as http;
import 'package:mocktail/mocktail.dart';
class MockClient extends Mock implements http.Client {}
final mockClient = MockClient();
final List Function(Invocation)> answers = [
(_) => throw
test('Adding data manually', () async {
final MockClient ghibliMock = MockClient();
when(ghibliMock.films).thenReturn(FilmModel(
director: 'test director',
description: 'test',
releaseDate: 'test',
producer: 'test'
)
class MockClient extends Mock implements GhibliFilms {
@override
Future> getFilms() async {
return Future.value(null); // this is not that important
}
}
void main() {
final GhibliFilms ghibliMock = MockClient();
// async
class MockClient extends Mock implements Client {
MockClient({
this.mockedResult,
this.mockedStatus = 200,
});
final Map mockedResult;
final int mockedStatus;
@override
Future send(BaseRequest request) {
return Fut
jest.fn(function () {
return this;
});
// module scope
jest.mock('../../config', () => ({
__esModule: true,
default: mockClient
});
const mockClient = {
items: jest.fn(),
type: jest.fn(),
...
};
...
Client mockClient = Mockito.mock(Client.class);
@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);
PowerMockito.mockStatic(ClientBuilder.class);
PowerMockito.when(ClientBuilder.newCli
// build.gradle
...
dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.google.code.gson:gson:2.8.5'
}
import 'package:http/testing.dart';
import 'package:http/http.dart';
MockClient integrationTestMockClient = MockClient((request) async {
switch (request.url.toString()) {
case 'https://staging.company.com/api/customer/123':
re
const client = {
items: () => {
return client;
},
type: (name: string) => {
return client;
},
toObservable: () => {
return client;
},
subscribe: handler => {
handler();
return client;
}
};
e
import 'package:flutter/widgets.dart';
import 'package:flutter_driver/driver_extension.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:utgard/business/config/globals.dart';
import 'package:utgard/main.da
Community Discussions
Trending Discussions on RxAndroidBle
QUESTION
I am trying to send the 128
bytes of the block to BLE Controller using the RxAndroidBle
library. the flow to send data from mobile to BLE controller is as follows
- Connect with BLE Controller
- Start OTA (sending 1)
- Send CRC (of the data block)
- Send data block
- wait for 2 seconds
- repeat step 3
- END OTA (sending 2)
Here is snapshot of a code
...ANSWER
Answered 2022-Jan-02 at 10:07You can use flatMapIterable()
with toList()
. Try to add toList()
operator before OTA_DATA_END
command like:
QUESTION
I have an IoT device with BLE on it and also I have a smartphone which support BLE protocol. I am using RxAndroidBle: com.polidea.rxandroidble2:rxandroidble:1.11.1 The problem is to communicate each other. I have established connection:
...ANSWER
Answered 2021-May-13 at 19:25Is there a way to send data every 300 ms to IoT device?
Of course there is. If there is no external source of the data to send one could use code similar to:
QUESTION
i have been using rxAndroidBLE lib on my android app to scan and connect to BLE devices. i know that location permission and location services needs to be enabled to scan nearby BLE devices but if i just want to connect to nearby BLE devices with it's macID(that i already know) is it still require to ask user to provide location permission and enable location services?
i have tried to connect to BLE device with it's MACID without granting Location permission or enabling Location services still i'm able to connect to BLE device on my device(Samsung S20) but some of our users are not able to connect to their BLE device.
...ANSWER
Answered 2021-Apr-16 at 19:52No it's not required, but please see https://stackoverflow.com/a/57099437/556495 why you can't always connect using only the Bluetooth Device Address.
QUESTION
I am using RXAndroidBle library to connect and read data from the BLE device. I have set the establishConnection
function to true
i.e. auto-connect to true. when the BleAlreadyConnectedException
is occurring I want to capture that exception and restart the flow of reading data because every time disposing and connecting to BLE device is creating issues. so better to keep the connection alive and re-read the data.
In onErrorResumeNext
i to re-call the functions writeStatus, readModelInfo,getReadings and so on. Now sure how would I achieve it.
ANSWER
Answered 2021-Feb-16 at 09:27Put the onErrorResumeNext
closer to the connection code.
QUESTION
I am creating a RxJava2
chain where in I want to enable and disable notification. the flow I am setting is as follows.
- establish a connection.
- set the notification to
READ_STATUS UUID
. - if the returned byte is
zero
then perform a write byte01
toWRITE_STATUS UUID
and afterWRITE_STATUS
, enable the notification ofREAD_STATUS UUID
to verify it has byte value1
. - else if the returned byte is
1
then just enable other indicators (UUID1
,UUID2
,UUD3
) and read the value.
I have a problem at step 2 and 3 where I am reading the value of READ_STATUS UUID
by enabling the notification. in order to re-read the value, I probably need to disable the notification and then again enable it. And to disable to the notification I have to dispose that particular setupNotification
.
Code is as follows
...ANSWER
Answered 2021-Jan-20 at 16:36To unsubscribe or to dispose setupNotification
or setupIndication
one can use the following code. I am sure there could be different ways but so far I could find this
QUESTION
I use RXAndroidBle to connect to Bluetooth devices. I use establishConnection
to get the connection observable and want to convert this Observable to an Completable. This code works and the completable completes as expected:
ANSWER
Answered 2020-Dec-07 at 14:26QUESTION
I have a rather long chain of Rx operations for my initial scan, connection and authorization. Here's the code.
...ANSWER
Answered 2020-Sep-28 at 17:45The reason why you cannot start a new scan lays in how you dispose the previous one. If you would look into the implementation or CompositeDisposable.add()
Javadoc you would see that:
QUESTION
I have a setup with two Android devices: an android phone and a custom hardware running Android 10. The latter acts as a BLE Server, which is discoverable always with the same static MAC address. Also when that custom HW is paired with the phone it has access to phone's contacts and calls history. That HW can also play media (sound) streamed from the phone.
I use RxAndroidBle 1.11.0 library for BLE communication. As soon as I exchange some data via BLE Characteristic I unsubscribe from the RX observable so the library effectively calls: bluetoothGatt.disconnect()
then blutetoohGatt.close()
(all those inside the DisconnectOperation
class).
My problem is the fact that based on my observations, calling blutetoohGatt.disconnect()
disconnects the classic BT profile (PBAP) as well.
Is it an expected behaviour?
I have investigated the code of generic Android P framework and it looks that calling bluetoothGatt.disconnect() -> bluetoothGatt.close()
completely disconnects the device described by the given MAC Address:
BluteoothGatt#disconnect()
BlutetoothGatt#close()
BlutetoothGatt#unregisterApp()
I would risk a statement that I have quite unusual BLE use-case scenario where the phone (Central/Client) and the peripheral (custom Android HW/Server) are connected simultaneously via Classic BT profile and via BLE. I suspect that disconnecting/closing device using its BT MAC address disconnect both profiles, hence the contacts sharing stops working. Is it possible to disconnect BLE connection only, but not affect the classic BT (SPP/PBAP) connections between the two devices?
...ANSWER
Answered 2020-Sep-25 at 09:45After further investigation described on that Github issue I realised that my custom hardware is equipped with dual-mode BT adapter so it supports classic BT (BR/EDR) and the BLE one. As soon as I pair an Android phone with the custom hardware via System Settings, classic BT profiles are bonded, but also my GATT Server advertises relevant services using the same MAC address which is used by the BR/EDR. Disconnecting BLE client connection disconnect BD/EDR as well.
What helps in my case is to not start pairing via System Settings, but let the GATT server advertise and let my BLE client app to connect (and trigger pairing) first. As a result I have a BLE connection with server available under "AA:AA:AA:AA:xx", while the classic BT profiles are connected to "BB:BB:BB:BB:yy" interface on the custom hardware. Now, disconnecting BLE profile does not disconnect the classic one.
I am looking for a solution which would allow my GATT Server to be advertised with BLE only, but no luck so far. Here are some interesting links I have found:
connectGatt creates connection over BT Classic instead of BLE
QUESTION
I am using RxAndroidBle library for communication with BLE device. The goal is to perform BLE scan, find device and establish connection to it. I am using autoConnect = true to keep connection running in background, however, I noticed that, sometimes, this method is getting blocked (I have 60 seconds timeout) and it times out. Also, when nRF Connect is running in background, it seems the connection succeed. Here is the log when issue occurs:
...ANSWER
Answered 2020-Jul-30 at 21:15When using autoConnect = true
Android uses relaxed initial scan parameters. Depending on how robust your mobile Bluetooth chipset is and what are the advertising parameters of your peripheral the connecting process may take even many minutes.
So, is there a way to improve the connection parameters from the app side, to make connection more aggressive or something similar?
Yes, use autoConnect = false
. This makes initial (implicit) scanning more aggressive but limits its time to 30 seconds. This is how Android did implement it.
Does nRF Connect do something different than what library does, so it makes app connecting faster to device?
If you have nRF Connect
opened in the background — be aware that it "steals" BLE connections. I.e.:
- Your peripheral is disconnected
- Open
nRF Connect
- Put
nRF Connect
to background - Open your app
- Connect your peripheral
- Close your app
- Observe that your peripheral is connected to the phone until
nRF Connect
is not killed or you do not manually disconnect your peripheral from it
QUESTION
I'm trying to add a delay in between each batch write and I managed to get it working by modifying this example but I'm not sure this is the correct way to achieve this?
...ANSWER
Answered 2020-Apr-15 at 10:27Your approach would delay next (sub)writes if Observable.timer().repeat()
would emit after the booleanObservable
. Unfortunately that would work only for the second (sub)write as after that .repeat()
would start to emit very quickly as it does not resubscribe to the upstream Observable
. From .repeat()
Javadoc:
Returns an Observable that repeats the sequence of items emitted by the source ObservableSource indefinitely.
If you would use Observable.timer(delayInMillis, MILLISECONDS).repeatWhen(completions -> completions)
or Observable.interval(delayInMillis, MILLISECONDS)
then these would make writes happen not more frequent than delayInMillis, MILLISECONDS
apart.
If you would like to give the peripheral delayInMillis, MILLISECONDS
time before issuing next write then there seems to be a simpler approach:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RxAndroidBle
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page