I’m trying to get a step count from Samsung Health using Xamarin Forms (for an Android App).
I tried using SamsungHealthForXamarin to recreate the SimpleHealth sample project from the Samsung Health SDK.
The Java sample project uses anonymous inline classes within the same scope that we can't do in C#. So it appears you have to build out an IConnectionListener interface instead.
Does anyone have any experience getting "step data" from Samsung Health using Xamarin Forms (C#) ? I’d love to see a super simple example of just getting today's step count in C#. It doesn't seem like it should be so difficult.
If I have understood you correctly, your issue is mostly with how to have the connection listener know what exactly its data store is. Starting from the fact that all listeners on Java are simply a class in C#, that implements the needed interface, we can create our listener like so:
The important line is the third one - the internal property
Store
. Here we will keep a reference to ourHealthDataStore
, which will depend on our listener.Our service will look like this:
Again, the important line is the third line from the method - we are assigning the store to our listener's property, so that we can have its reference there.
The same approach will go for the StepCountReporter class:
You will need 2 additional classes here -
StepResultHolderResultListener
&StepObserver
StepResultHolderResultListener
StepObserver
After that, you can notify the UI in whatever way you wish - using Xamarin's MessagingCenter, using events, using some other kind of observer logic - depending on your project's architecture.
A few side notes on the topic:
README.md