Android 蓝牙:未发现 phone
Android Bluetooth: Not discovering phone
按照指南 here,我创建了一个应用程序,用于查找附近的蓝牙设备并将它们的名称(如果可用)、地址和 rssi 记录到一个简单的列表视图中。
我的目标是过滤结果以找到附近所有可发现的 phone 及其 RSSI。但是,我没有在附近的其他设备列表中看到我的 iPhone。我通过设置->常规->关于知道我的 phone 的 MAC 地址,我的 phone 有 bluetooth enabled and is discoverable。
我的 phone 距离设备大约一英尺远,因此设备应该能够捡起它(它可以从房间的另一端发现我的笔记本电脑)。我怎样才能确保找到我的 phone 和其他 phone?
注意:我正在用 c# 和 Xamarin.Android 开发 Android 版本 6.0.1。
更新:
这是我用来发现的代码-
static int REQUEST_ENABLE_BT = 1;
BluetoothBroadcastReceiver btReceiver;
BluetoothAdapter btAdapter = BluetoothAdapter.DefaultAdapter
//check status of bluetooth and enable if possible
...
//Discover bluetooth devices
btReceiver = new BluetoothBroadcastReceiver(this);
IntentFilter filter = new IntentFilter(BluetoothDevice.ActionFound);
RegisterReceiver(btReceiver, filter);
btAdapter.StartDiscovery();
//custom BroadcastReceiver to take ActionFound
public class BluetoothBroadcastReceiver : BroadcastReceiver
{
Activity activity;
public BluetoothBroadcastReceiver(Activity activity)
{
this.activity = activity;
}
public override void OnReceive(Context context, Intent intent)
{
string action = intent.Action;
if (BluetoothDevice.ActionFound.Equals(action))
{
//Discovery has found a device. Get info
BluetoothDevice device = (Android.Bluetooth.BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
string deviceName = device.Name;
string deviceAddress = device.Address;
short RSSI = intent.GetShortExtra(BluetoothDevice.ExtraRssi,(short)0);
string result = deviceName + " " + deviceAddress + " " + RSSI;
newDevicesArrayAdapter.Add(result);
}
}
}
谢谢!
上面的代码可以正确发现附近处于 "discoverable" 模式的设备。但是,似乎在导航到蓝牙设置页面之前,手机实际上是不可发现的。
至少不是 iPhone 7/8 或三星盖乐世 S8。
按照指南 here,我创建了一个应用程序,用于查找附近的蓝牙设备并将它们的名称(如果可用)、地址和 rssi 记录到一个简单的列表视图中。
我的目标是过滤结果以找到附近所有可发现的 phone 及其 RSSI。但是,我没有在附近的其他设备列表中看到我的 iPhone。我通过设置->常规->关于知道我的 phone 的 MAC 地址,我的 phone 有 bluetooth enabled and is discoverable。
我的 phone 距离设备大约一英尺远,因此设备应该能够捡起它(它可以从房间的另一端发现我的笔记本电脑)。我怎样才能确保找到我的 phone 和其他 phone?
注意:我正在用 c# 和 Xamarin.Android 开发 Android 版本 6.0.1。
更新: 这是我用来发现的代码-
static int REQUEST_ENABLE_BT = 1;
BluetoothBroadcastReceiver btReceiver;
BluetoothAdapter btAdapter = BluetoothAdapter.DefaultAdapter
//check status of bluetooth and enable if possible
...
//Discover bluetooth devices
btReceiver = new BluetoothBroadcastReceiver(this);
IntentFilter filter = new IntentFilter(BluetoothDevice.ActionFound);
RegisterReceiver(btReceiver, filter);
btAdapter.StartDiscovery();
//custom BroadcastReceiver to take ActionFound
public class BluetoothBroadcastReceiver : BroadcastReceiver
{
Activity activity;
public BluetoothBroadcastReceiver(Activity activity)
{
this.activity = activity;
}
public override void OnReceive(Context context, Intent intent)
{
string action = intent.Action;
if (BluetoothDevice.ActionFound.Equals(action))
{
//Discovery has found a device. Get info
BluetoothDevice device = (Android.Bluetooth.BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
string deviceName = device.Name;
string deviceAddress = device.Address;
short RSSI = intent.GetShortExtra(BluetoothDevice.ExtraRssi,(short)0);
string result = deviceName + " " + deviceAddress + " " + RSSI;
newDevicesArrayAdapter.Add(result);
}
}
}
谢谢!
上面的代码可以正确发现附近处于 "discoverable" 模式的设备。但是,似乎在导航到蓝牙设置页面之前,手机实际上是不可发现的。
至少不是 iPhone 7/8 或三星盖乐世 S8。