【问题标题】:Android JB broadcast receiver not receiving bluetooth.android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTEDAndroid JB 广播接收器未接收到 bluetooth.android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED
【发布时间】:2012-08-28 23:16:41
【问题描述】:

我正在使用运行 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>

这是接收器

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");
            }
        }

【问题讨论】:

  • 你有没有在 pre-JB 上尝试过同样的应用程序?换句话说,问题出在JB还是上面的代码?

标签: android bluetooth broadcastreceiver android-4.2-jelly-bean


【解决方案1】:

这是正在广播的新意图。

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

感谢关注 这是新的意图

【讨论】:

    【解决方案2】:

    我不知道我是否正确,但我认为这行是错误的:

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

    应该是这个:

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

    其他人也一样。将“蓝牙设备”更改为“设备”。

    在广播中也有类似的东西:

    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

    【讨论】:

    • 非常感谢!浪费了几个小时来弄清楚为什么我的 BroadcastReceiver 注册动态接收动作,而不是清单中定义的静态动作。
    • 这个解决方案对我不起作用(Nexus 6 Lollipop)。请参阅我的答案以获取更新的解决方案。
    【解决方案3】:

    您的意图过滤器操作不正确。您实际上想要使用以下内容:

    &lt;action android:name="android.bluetooth.device.action.ACL_CONNECTED" /&gt;

    您可以在official Android BluetoothDevice documentation 中找到这些值(查看常量值)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多