Conflict between using xamarin and using tizen..?

Hello there,

I quite confused, I am using both:

using Xamarin.Essentials;
using Tizen.Sensor;

Tizen.Sensor for BPM funcions (I dont find any in xamarin essentials)
and Xamarin Essentilas for other, like sending sms and others.

Now I want implement Accelerometer (https://docs.microsoft.com/en-gb/xamarin/essentials/accelerometer?context=xamarin/xamarin-forms) but It has conflict with Tizen.Sensor accordings:

|
Error|CS0104|‘Accelerometer’ is an ambiguous reference between ‘Xamarin.Essentials.Accelerometer’ and 'Tizen.Sensor.Accelerometer

Is there any hack… Or some explanations, Or I cant use both…?

[moved to Galaxy Watch -Tizen.net Forum - Ron]

Hello again, I think I understand this bit more and create new class for accelerometer functions and from mainpage I can “call” for this function, but I cant figure out, how to get data from this class, specificaly from non returning method.

My structure is:

MainPage.cs (+ xaml)
/classes/Accelerometer.cs

This is Accelerometer class:

public string GetData()
    {
        return "123";

        // this is working, when I call this from mainpage like this:
        // var r = new classes.GetData();
        // showAcc1.Text = r.GetData();
    }

    void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e)
    {
        var data = e.Reading;

        var accX = data.Acceleration.X.ToString();
        var accY = data.Acceleration.Y.ToString();
        var accZ = data.Acceleration.Z.ToString();
        
        // How to get or push this variables to MainPage.cs so I can work with them on main screen of my app?

    }

Hi,
How about using event handler to handle the data? Check the following page, the Subscribing to Sensor Events section may help you to solve your problem.

Here you will find sample applications. Check the code in github, this will help you.

Thank you, I figure out, that I can use it right into MainPage.cs

    public void StartAccelerometer()
    {
        SensorSpeed speed = SensorSpeed.Default; // Set speed delay for monitoring changes.
        Xamarin.Essentials.Accelerometer.Start(speed);
    }

    private void AccelerometerReadData()
    {
        Xamarin.Essentials.Accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
    }

    private void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e)
    {
        var data = e.Reading;
        
        var accX = data.Acceleration.X.ToString();
        var accY = data.Acceleration.Y.ToString();
        var accZ = data.Acceleration.Z.ToString();
1 Like

Hi,
You do not have to use everything inside the MainPage.cs. You can use various model like MVVM and other model. That will create your code more manageable. In the sample applications list you may find different approach to handle this.

By the way it’s great that you figure out the solution :smile:

OK so maybe you can explain me this?

In App.cs:

    public App()
    {
        InitializeComponent();
        MainPage = new Pulsometer.MainPage();
    }

    protected override void OnStart()
    {
        // Handle when your app starts
        var sms_number = MainPage.GetSMSNumber();
        SettingsPage.SendSms(sms_number, "test");
    }

I try get my phone number to variable. I need call public function GetSMSNumber() which is on MainPage.cs

   public string GetSMSNumber() 
   {...}

I can’t call this like above var sms_number = MainPage.GetSMSNumber();
But I can call the SendSms function simply like SettingsPage.SendSms(); … ?

This is what I quite don’t understand how it works.

The error is:

|Error|CS1061|'Page' does not contain a definition for 'GetSMSNumber' and no accessible extension method 'GetSMSNumber' accepting a first argument of type 'Page' could be found (are you missing a using directive or an assembly reference?)

Hi,
I hope your MainPage class is inside the Pulsometer namespace. In that case you need to call the function as bellow.

var sms_number = new Pulsometer.MainPage().GetSMSNumber();

In OnStart() method there is no object exsits called MainPage. You have to establish link properly with that class to call the method inside it.

I hope this may help you.

1 Like

YES! I understand this better now :slight_smile:

1 Like