'Open Xamarin App when Bluetooth device discovered

I created a simple App with Xamarin to connect to a Bluetooth LE device. It works ok, I can search for devices, and once the desired one is found, connect to it and send/receive data with GATT transactions.

What I'd like to do now is that my App starts when certain BLE device is found. As far as I look for, I can't find any way to do it.

One approach is to do a development for running in the background and scan for devices periodically and another approach is to use Apps like Tasker or IFTT that will start my App.

Given that the phone is listening for Bluetooth devices continuously, I guess coding something in the background is redundant and I prefer not using third party apps.

So, is it there any way to somehow subscribe to the OS of the phone in order it starts my app when a specific BLE device is found? If not, which is the best approach?



Solution 1:[1]

You can use the Process class for this in your app. After the BLE device is found make sure to check if the application you want to start isn’t already running.

   using System.Diagnostics;
// as example we use notepad.exe

if(deviceFound)
{
    Process[] pname = Process.GetProcessesByName("notepad");
    if (pname.Length == 0)
    {
        Process.Start(@"C:\Windows\notepad.exe");
    } 
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GrooverFromHolland