我正在使用运行jb的扎根三星galaxy nexus手机,由于某种原因,我没有从蓝牙连接服务接收任何广播意图。您将在下面找到我的接收器清单和广播接收器代码。任何提示或想法将不胜感激。
由于
这是清单
<receiver android:name=".ABroadcastReciever" >
<intent-filter>
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED" />
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED" />
<action android:name="android.bluetooth.BluetoothDevice.ACTION_BOND_STATE_CHANGED" />
<action android:name="android.bluetooth.BluetoothDevice.ACTION_FOUND" />
<action android:name="android.bluetooth.BluetoothDevice.BOND_BONDING" />
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
这是Reciever
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//This is looking for the Wifi Connectivity Changes
if(action.equals("android.net.conn.CONNECTIVITY_CHANGE")){
Log.d(TAG,"received: Wifi Connection Change");
}
//This is looking Bluetooth connection disconnect
else if(action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED") ||
action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED_REQUESTED") ){
Log.d(TAG,"Received: Bluetooth Disconnected");
}
//This is looking for Bluetooth connection established
else if(action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED")){
Log.d(TAG,"Received: Bluetooth Connected");
}
}
答案 0 :(得分:2)
这是正在播放的新意图。
<action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" />
感谢您的关注 这是新的意图
答案 1 :(得分:1)
我不知道我是否正确,但我认为这一行是错误的:
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED" />
应该是这个:
<action android:name="android.bluetooth.device.ACTION_ACL_CONNECTED" />
与其他人一样。更改“设备”的“BluetoothDevice”。
在广播中也是类似的事情:
if(action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED"))
应该是
if(action.equals("android.bluetooth.device.action.ACL_CONNECTED"))
为device.action.ACL_CONNECTED更改BluetoothDevice.ACTION_ACL_CONNECTED
答案 2 :(得分:0)
您的意图过滤器操作不正确。您实际上想要使用以下内容:
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
您可以在official Android BluetoothDevice documentation中找到这些值(查看常量值)。