简体   繁体   English

发现蓝牙设备时打开 Xamarin App

[英]Open Xamarin App when Bluetooth device discovered

I created a simple App with Xamarin to connect to a Bluetooth LE device.我用 Xamarin 创建了一个简单的应用程序来连接蓝牙 LE 设备。 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.它工作正常,我可以搜索设备,一旦找到所需的设备,就连接到它并使用 GATT 事务发送/接收数据。

What I'd like to do now is that my App starts when certain BLE device is found.我现在想做的是当找到某个 BLE 设备时我的应用程序启动。 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.一种方法是进行开发以在后台运行并定期扫描设备,另一种方法是使用 Tasker 或 IFTT 等应用程序来启动我的应用程序。

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?那么,有没有办法以某种方式订阅手机的操作系统,以便在找到特定的 BLE 设备时启动我的应用程序? If not, which is the best approach?如果不是,最好的方法是什么?

You can use the Process class for this in your app.您可以在您的应用程序中为此使用流程 class。 After the BLE device is found make sure to check if the application you want to start isn't already running.找到 BLE 设备后,请务必检查您要启动的应用程序是否尚未运行。

   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");
    } 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用 Xamarin 应用程序监视 Android 设备上所有打开的应用程序吗? - Can I monitor all open apps on an android device with a Xamarin app? Xamarin Android蓝牙应用程序崩溃 - Xamarin Android Bluetooth app crash 在将Xamarin应用程序部署到设备时,Visual Studio 2015有时会冻结 - Visual Studio 2015 sometimes freezes when deploying Xamarin app to device 当我在 Xamarin Android 应用程序中监听蓝牙设备时,如何防止主线程阻塞? - How to prevent main thread from blocking when I am listening on bluetooth devices in a Xamarin Android app? Xamarin Forms - 如何使点击 email 链接的用户在 C7B83F57C37361AC7BA39 应用程序中打开 C7EBA39 应用程序 - Xamarin Forms - How to make it so that a user that clicks on a email link will open the email app in the device Xamarin应用程序可在模拟器上运行,但不能在设备上运行 - Xamarin app works on emulator but not on device 如何在 Xamarin Forms App 中拦截 Android 设备音量增大/减小按钮以打开相机? - How to Intercept Android Device Volume Up/Down Buttons to Open Camera in Xamarin Forms App? 如何通过蓝牙扫描另一台设备- Xamarin - How to scan for another device through Bluetooth- Xamarin 使用Xamarin Crossplatform在应用程序不在设备的最新历史记录中时如何显示本地通知 - How to display local notification when the app is not in the recent history of the device using Xamarin Crossplatform xamarin 表单 — 检测外部蓝牙“打开”并在应用程序中相应地切换“开关” - xamarin forms — detect external bluetooth 'turn on' and toggle 'switch' accordingly in the app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM