Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 6.0蓝牙程序无法发现任何可用的蓝牙设备_Android_Bluetooth_Android 6.0 Marshmallow_Android Permissions - Fatal编程技术网

Android 6.0蓝牙程序无法发现任何可用的蓝牙设备

Android 6.0蓝牙程序无法发现任何可用的蓝牙设备,android,bluetooth,android-6.0-marshmallow,android-permissions,Android,Bluetooth,Android 6.0 Marshmallow,Android Permissions,目标 发现所有可用的蓝牙设备,例如打开蓝牙的我的iPad(可发现)。 ANDROID版本 6.0 问题 无法发现任何蓝牙设备。 代码 // Permission <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> public BroadcastRec

目标

发现所有可用的蓝牙设备,例如打开蓝牙的我的iPad(可发现)。

ANDROID版本

6.0

问题

无法发现任何蓝牙设备。

代码

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

我看到程序没有进入“动作”的条件块,但我的iPad的蓝牙已打开,问题来自何处?

如果使用Android 6,请添加以下权限之一:

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

并打开定位服务(GPS):

并打开位置权限:

谷歌现在需要
ACCESS\u FINE\u LOCATION
ACCESS\u COARCE\u LOCATION
权限才能扫描蓝牙或Wifi设备。这是一种奇怪的行为,但谷歌表示,从现在起,它应该这样做


我已经添加了您记忆中的两个权限,但结果似乎相同。请确保您通过设置启用了gps和应用程序的所有权限不确定是否有用,但我在Android 7.0中遇到了类似问题,我确实需要为我的应用程序启用位置权限,但不需要实际打开位置。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCTION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />