请记住,Xamarin绑定到本机api所以不要担心某些“与本机方式有关”;)基于你引用的anwser我编写并测试了下面的代码 . 我希望它会对你有所帮助 .
class btListener : Java.Lang.Object, IBluetoothProfileServiceListener
{
public void OnServiceConnected([GeneratedEnum] ProfileType profile, IBluetoothProfile proxy)
{
String deviceName = "JABRA WAVE+";
BluetoothDevice result = null;
var devices = BluetoothAdapter.DefaultAdapter.BondedDevices;
if (devices != null)
{
foreach (BluetoothDevice device in devices)
{
if (deviceName == device.Name)
{
result = device;
break;
}
}
}
var connect = Java.Lang.Class.FromType(typeof(BluetoothA2dp)).GetDeclaredMethod("connect", Java.Lang.Class.FromType(typeof(BluetoothDevice)));
connect.Invoke((Java.Lang.Object)proxy, result);
}
public void OnServiceDisconnected([GeneratedEnum] ProfileType profile)
{
}
}
以下代码如下OnCreate功能:
btListener btReceiver = new btListener();
BluetoothAdapter.DefaultAdapter.GetProfileProxy(this, btReceiver, ProfileType.A2dp);
只是看了一下日期..但我还是张贴了答案 - 也许它仍然会帮助某人