简体   繁体   中英

Android Bluetooth: Not discovering phone

Following the guide here , I have created an application that finds the nearby bluetooth devices and records their name(if available), address, and rssi to a simple listview.

My goal is to filter the results to find all of the nearby phones that are discoverable and their RSSI. However, I do not see my iPhone in the list with the other nearby devices. I know the MAC address of my phone via settings->general->about and my phone has bluetooth enabled and is discoverable .

My phone is about a foot away from the device, so the device should be able to pick it up (It can discover my laptop from across the room). How can I ensure that I find my phone and other phones?

Note: I am developing in c# and Xamarin.Android for Android version 6.0.1.

UPDATE: This is my code used to make the discovery-

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

Thanks!

The code above is correct to discover the nearby devices that are in "discoverable" mode. However, it seems that phones are not actually discoverable until they are navigated to their bluetooth setting page.

At least not iPhone 7/8 or Samsung Galaxy S8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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