Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.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
Java 蓝牙设备连接问题_Java_Android_Bluetooth_Android Bluetooth - Fatal编程技术网

Java 蓝牙设备连接问题

Java 蓝牙设备连接问题,java,android,bluetooth,android-bluetooth,Java,Android,Bluetooth,Android Bluetooth,我正在开发一个android应用程序,我正在检查两台设备是否通过蓝牙连接 我正在使用以下代码注册广播接收器 IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED); IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED); this.registerReceiver(

我正在开发一个android应用程序,我正在检查两台设备是否通过蓝牙连接

我正在使用以下代码注册广播接收器

    IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
    IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);

    this.registerReceiver(mReceiver, filter1);
    this.registerReceiver(mReceiver, filter2);
广播接收器看起来像这样

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        // When discovery finds a device

        if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action))
        {   
            Log.e("bluetooth connected","bluetooth connected");
        }
        else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action))
        {
            Log.e("bluetooth not connected","bluetooth not connected");
        }    
    }
};

无论如何,这是行不通的。我不知道我会错在哪里。请帮忙!谢谢

您的清单中有蓝牙权限吗

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

你试过蓝牙管理员权限吗

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


Android文档声明“ACL连接由Android蓝牙堆栈自动管理”。很可能,不希望在应用程序级别对它们进行管理<代码>蓝牙设备。ACTION\u ACL\u CONNECTED和
蓝牙设备。ACTION\u ACL\u DISCONNECTED
调度取决于设备和固件版本(例如,我体验到Nexus S正确地调度它们,而较旧的GT-I5800则不正确)。

我添加了权限并使用了上述相同的代码。不工作。它不是在呼叫广播接收器!!对我已添加此权限。
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />