简体   繁体   English

使用Xamarin使用蓝牙发现设备

[英]Discover devices using bluetooth with xamarin

Following the Android guide I've created an app to connect a smartphone to a specific device using bluetooth. 按照Android 指南,我创建了一个应用程序,用于使用蓝牙将智能手机连接到特定设备。

However it has a problem, the scan for nearby devices doesn't detect all the devices every time. 但是,这有一个问题,对附近设备的扫描不会每次都检测到所有设备。 Sometimes it returns all the devices, sometimes it returns only a few. 有时它返回所有设备,有时仅返回一些设备。 I'm running Android 6.0 and I've set all the permissions needed. 我正在运行Android 6.0,并且已设置所有必需的权限。

I see the same behavior with my phone bluetooth search (outside the application). 我在手机蓝牙搜索中(应用程序外部)看到了相同的行为。 This makes me wonder if the problem is in my code or is in fact a problem in android. 这使我想知道问题出在我的代码中还是实际上是android中的问题。

Has anyone had a similar problem? 有人遇到过类似的问题吗?

If your code's able to discover through available devices then it's alright. 如果您的代码能够通过可用的设备发现,那就没问题了。 I've used few times code from guide you've provided and everything was alright. 我已经使用了几次您提供的指南中的代码,一切都很好。 Bluetooth time discovering could be important here. 蓝牙时间发现在这里可能很重要。 Maybe try to set something like TIMEOUTMILISEC for longer then it is. 也许尝试将TIMEOUTMILISEC之类的时间设置得更长一些。 For example: 例如:

Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM