Android 6.0 Bluetooth cannot detect any available Bluetooth devices

TARGET

Discovery of all available Bluetooth devices, such as my iPad, with bluetooth enabled (available for discovery).

ANDROID VERSION

6.0

PROBLEM

Unable to open Bluetooth devices.

CODE

// Permission
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

public BroadcastReceiver mReceiver;
public IntentFilter filter;

private boolean discover_AvailableBluetoothDevice() {
        mReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                Log.d(TAG, "onReceive Called");
                String action = intent.getAction();
                // When discovery finds a device
                if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
                    Log.d(TAG, "ACTION_DISCOVERY_STARTED");
                } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
                    Log.d(TAG, "ACTION_DISCOVERY_FINISHED");
                } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    Log.d(TAG, "ACTION_FOUND");
                    // Get the BluetoothDevice object from the Intent
                    BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    // Add the name and address to an array adapter to show in a ListView
                    String str = device.getName() + "\n( " + device.getAddress() + " )";
                    adapter.add(str);
                }
            }
        };

        filter = new IntentFilter();
        filter.addAction(BluetoothDevice.ACTION_FOUND);
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
        registerReceiver(mReceiver, filter);
        boolean isSuccessDiscovery = mBluetoothAdapter.startDiscovery();
        return isSuccessDiscovery;
    }



EXECUTION OF RESULTS (logcat)

02-02 01:17:26.142 7194-7194/eie.imt.smartswitch D/†MainActivity: This device support Bluetooth.
02-02 01:17:55.052 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: isSuccessDiscovery=true
02-02 01:17:55.147 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: onReceive Called
02-02 01:17:55.147 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: ACTION_DISCOVERY_STARTED
02-02 01:18:07.909 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: onReceive Called
02-02 01:18:07.910 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: ACTION_DISCOVERY_FINISHED

I see that the program is not included in the ACTION_FOUND condition block , but my bluetooth iPad is on, where does the problem arise?

+4
source share
1 answer

If you are using Android 6, add one of the following permissions:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCTION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

And turn on the location service (GPS):

enter image description here

:

enter image description here

Google ACCESS_FINE_LOCTION ACCESS_COARCE_LOCATION Bluetooth Wi-Fi-. , Google , .

AndroidDev

+11

Source: https://habr.com/ru/post/1626892/


All Articles