Android Xamarin应用程序没有';无法识别任何蓝牙设备(Plugin.BluetoothLE)
我正在使用Plugin.BluetoothLE与arduino项目一起制作应用程序。所以对于移动应用,我使用Xamarin表单和Plugin.BluetoothLE库。问题是我的移动设备无法识别任何蓝牙设备。这是我扫描设备的视图模型中的代码片段Android Xamarin应用程序没有';无法识别任何蓝牙设备(Plugin.BluetoothLE),android,xamarin,xamarin.forms,xamarin.android,bluetooth,Android,Xamarin,Xamarin.forms,Xamarin.android,Bluetooth,我正在使用Plugin.BluetoothLE与arduino项目一起制作应用程序。所以对于移动应用,我使用Xamarin表单和Plugin.BluetoothLE库。问题是我的移动设备无法识别任何蓝牙设备。这是我扫描设备的视图模型中的代码片段 private void BtnFindHandler() { if (CrossBleAdapter.Current.Status != AdapterStatus.PoweredOn) { Debug.WriteLine("Bluet
private void BtnFindHandler()
{
if (CrossBleAdapter.Current.Status != AdapterStatus.PoweredOn)
{
Debug.WriteLine("Bluetooth is not turned on.");
return;
}
if (CrossBleAdapter.Current.IsScanning)
CrossBleAdapter.Current.StopScan();
var scanner = CrossBleAdapter.Current.Scan().Subscribe(scanResult =>
{
if (scanResult.Device.Name != null)
Debug.WriteLine(scanResult.Device.Name);
});
}
这是我的Android清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.appname" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
<application android:label="TestArduino.Android" android:icon="@mipmap/ic_launcher"></application>
</manifest>
我还试图手动设置我的应用程序的权限,但没有成功。
非常感谢:)您需要向用户请求
位置
权限并授予它。清单中的蓝牙权限已足够,无需向用户请求
您可以使用它来实现这一点
如果你想知道为什么使用这个插件。
适用于蓝牙。
只需打开手机上的GPS。显然,在某些设备上,仅请求和允许位置权限是不够的。我尝试使用此插件,在扫描时,我已授予位置权限,但仍然不起作用。@Nenad您可以尝试在手机设置中手动授予权限,以便该应用程序进行检查。我也尝试过,没有成功。我将尝试使用比Android 6.0旧的手机,并将结果发布在这里。谢谢你的时间。@Nenad你可以试着在你的
订阅中记录异常。没有任何异常,只是不认识任何设备:(他使用的插件是一件大师级的主要艺术品,因此请不要毫无理由地建议交换。
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App(new AndroidInitializer()));
RequestPermissions(new[]
{
Manifest.Permission.AccessCoarseLocation,
Manifest.Permission.BluetoothPrivileged
}, 0);
}