1

我正在使用运行jb的根三星galaxy nexus手机,由于某些原因,我没有收到来自蓝牙连接服务的任何广播意图。下面你会发现我的接收器清单和广播接收器代码。任何提示或想法,将不胜感激。Android JB广播接收器没有收到bluetooth.android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED

感谢

这里是清单

<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

您是否在JB之前尝试过相同的应用程序?换句话说,JB是问题还是上述代码? – Tom

回答

2

这里是正在播出的新意图。

<action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" /> 

感谢这里看着 是新的意图

1

我不知道,如果我是正确的,但我认为,这条线是错误的:

<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED" /> 

它应该是这个一个:

<action android:name="android.bluetooth.device.ACTION_ACL_CONNECTED" /> 

与其他人一样的东西。更改“设备”的“BluetoothDevice”。

在broascast类似的还有同样的事情:

if(action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED")) 

应该

if(action.equals("android.bluetooth.device.action.ACL_CONNECTED")) 

变化BluetoothDevice.ACTION_ACL_CONNECTED为device.action.ACL_CONNECTED

+0

非常感谢!浪费了几个小时,弄清楚为什么我的BroadcastReceiver注册动态收到了动作,但没有在清单中定义的静态动作。 – stefan

+0

此解决方案对我无效(Nexus 6 Lollipop)。查看我的答案以获取更新的解决方案 –

0

你的意图过滤器的行为是不正确的。实际上,你要使用以下命令:

<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />

可以在official Android BluetoothDevice documentation找到这些值(看下恒定值)。