Android侦听操作\u停靠\u事件

Android侦听操作\u停靠\u事件,android,android-intent,broadcastreceiver,intentfilter,Android,Android Intent,Broadcastreceiver,Intentfilter,我正在尝试按和收听停靠更改事件 我的听筒从来没有被击中过 我的代码似乎很简单,所以我想知道监听dock事件是否需要权限?我是否遗漏了与行动码头事件相关的其他内容 AndroidManifest.xml <receiver android:enabled="true" android:exported="true" android:label="MyReceiver" android:name="path.to.MyReceiver"> <intent-filter>

我正在尝试按和收听停靠更改事件

我的听筒从来没有被击中过

我的代码似乎很简单,所以我想知道监听dock事件是否需要权限?我是否遗漏了与行动码头事件相关的其他内容

AndroidManifest.xml

<receiver android:enabled="true" android:exported="true" android:label="MyReceiver" android:name="path.to.MyReceiver">
  <intent-filter>
    <action android:name="android.intent.action.DOCK_EVENT"/>
  </intent-filter>
</receiver>

我正在将手机插入交流电源插座和macbook pro进行测试。我在Android 4.4.4上使用Moto X(第二代)。

底座是一种非常特殊的配件,如图所示:

  • 汽车
  • 书桌
  • 低端(模拟)办公桌
  • 高端(数字)办公桌
您会注意到,这些都与插入电源无关。为此,您可能希望使用一个意图过滤器,例如

<receiver android:name=".PowerConnectionReceiver">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
    <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
  </intent-filter>
</receiver>

<receiver android:name=".PowerConnectionReceiver">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
    <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
  </intent-filter>
</receiver>