vincentmasselis / rxbluetoothkotlin Goto Github PK
View Code? Open in Web Editor NEWBluetooth low energy reactive framework for Android written in Kotlin
License: Other
Bluetooth low energy reactive framework for Android written in Kotlin
License: Other
I got an issue in DeviceActivity of demoApp
.switchMapSingle { device.connectRxGatt(applicationContext as Application) }
Type mismatch: inferred type is Application but Boolean was expected
Also ScanActivty
.rxScan(this, flushEvery = 1L to TimeUnit.SECONDS)
Type mismatch: inferred type is ScanActivity but Pair<List, ScanSettings>? was expected
cf https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
I'll probably work on a pull request soon to handle the NeedBluetoothPermission case
\RxBluetoothKotlin-maven-central-migration\RxBluetoothKotlin-maven-central-migration\demo-app\app\src\main\java\com\vincentmasselis\demoapp\DeviceActivity.kt: (50, 14): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun Disposable.disposeOnState(exceptedState: ActivityState, activityToMonitor: Activity): Disposable defined in com.vincentmasselis.rxuikotlin
public fun Disposable.disposeOnState(exceptedState: FragmentState, fragmentToMonitor: Fragment): Disposable defined in com.vincentmasselis.rxuikotlin
public fun Disposable.disposeOnState(exceptedState: ViewHolderState, viewHolderToMonitor: LifecycleViewHolder): Disposable defined in com.vincentmasselis.rxuikotlin
When I call bluetoothManager.rxScan(context)
, and it appears "Cannot access class 'io.reactivex.Flowable'. Check your module classpath for missing or conflicting dependencies".
Some of the returned data cloud be transformed from data class
to value class
introduced in Kotlin 1.5, it will increase the global performance of the library when processing input and outputs of the android framework.
jCenter will be deprecated in 2022 and it no longer accept submissions in early 2021
##Code:
connectDisposable = connectState.filter { it is RXBleManager.ConnectStates.Connecting }
.switchMapSingle {
(connectState.value as? RXBleManager.ConnectStates.Connecting)?.device?.connectRxGatt(true)
}
.switchMapMaybe {
gatt -> gatt.whenConnectionIsReady().map { gatt }
}
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ gatt->
Toast.makeText(this, "Connected !", Toast.LENGTH_SHORT).show()
connectState.onNext(RXBleManager.ConnectStates.Connected(gatt))
Maybe
.defer {
if (gatt.source.services.isEmpty()) gatt.discoverServices()
else Maybe.just(gatt.source.services)
}.subscribe { serviceList ->
for (service in serviceList)
{
for (characteristic in service.characteristics){
if (containProperty(BluetoothGattCharacteristic.PROPERTY_NOTIFY,characteristic.properties)){
if (characteristic.descriptors.isEmpty()){
BuglyLog.i(tag,"no characteristic.descriptors")
continue
}
gatt.enableNotification(characteristic)
.flatMapPublisher {
gatt.listenChanges(it)
}
.subscribe ({ byteArray ->
//BuglyLog.d(tag,byteArray.toString())
},{//cash here
BuglyLog.e(tag,it.message)
it.printStackTrace()
})
}
}
}
}
},{
val message =
when (it) {
is BluetoothIsTurnedOff -> "Bluetooth is turned off"
is DeviceDisconnected -> "Unable to connect to the device"
else -> "Error occurred: $it"
}
AlertDialog.Builder(this).setMessage(message).show()
// bluetoothAdapter.disable()
// Handler().postDelayed(Runnable { bluetoothAdapter.enable() },500)
}
)
##Log
1 io.reactivex.exceptions.OnErrorNotImplementedException:The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | DescriptorNotFound(device=C7:E4:E3:E2:E1:FD, characteristicUUID=00010203-0405-0607-0809-0a0b0c0d2b17, descriptorUUID=00002902-0000-1000-8000-00805f9b34fb)
2 io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
3 ......
4 Caused by:
5 com.vincentmasselis.rxbluetoothkotlin.DescriptorNotFound:
6 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$rxChangeNotification$3.apply(RxBluetoothGattImpl.kt:517)
7 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$rxChangeNotification$3.apply(RxBluetoothGattImpl.kt:28)
8 io.reactivex.internal.operators.maybe.MaybeFlatten$FlatMapMaybeObserver.onSuccess(MaybeFlatten.java:88)
9 io.reactivex.internal.operators.observable.ObservableElementAtMaybe$ElementAtObserver.onNext(ObservableElementAtMaybe.java:82)
10 io.reactivex.internal.operators.observable.ObservableOnErrorNext$OnErrorNextObserver.onNext(ObservableOnErrorNext.java:68)
11 io.reactivex.internal.operators.observable.ObservableFlatMapSingle$FlatMapSingleObserver.innerSuccess(ObservableFlatMapSingle.java:151)
12 io.reactivex.internal.operators.observable.ObservableFlatMapSingle$FlatMapSingleObserver$InnerObserver.onSuccess(ObservableFlatMapSingle.java:284)
13 io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:67)
14 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$enqueue$1$1$singleToEnqueue$1.accept(RxBluetoothGattImpl.kt:203)
15 io.reactivex.internal.operators.single.SingleDoOnSuccess$DoOnSuccess.onSuccess(SingleDoOnSuccess.java:54)
16 io.reactivex.internal.operators.single.SingleTimeout$TimeoutMainObserver.onSuccess(SingleTimeout.java:141)
17 io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.onSuccess(SingleSubscribeOn.java:68)
18 io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:67)
19 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$rxChangeNotification$1.subscribe(RxBluetoothGattImpl.kt:511)
20 io.reactivex.internal.operators.single.SingleCreate.subscribeActual(SingleCreate.java:39)
21 io.reactivex.Single.subscribe(Single.java:3603)
22 io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
23 io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:124)
24 android.os.Handler.handleCallback(Handler.java:808)
25 android.os.Handler.dispatchMessage(Handler.java:101)
26 android.os.Looper.loop(Looper.java:166)
27 android.app.ActivityThread.main(ActivityThread.java:7529)
28 java.lang.reflect.Method.invoke(Native Method)
29 com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
30 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
I know it is listed as TODO
but in order to be used, a library needs a license file / description.
Please add one to your project (in the README or even better, in a specific LICENSE file)
Hi
I'm trying to establish BLE communication with an esp32. I succeed to do it in java but I'm trying to do it in Kotlin now. I run the demo app but it seems the Notifications are not used in the example. However I found a file named "ListenChangeTest.kt" I think the solution is in this file but I don't understand it. Can you explain how to use notifications in your example please ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.