【问题标题】:Can the Android emulator receive ACTION_POWER_CONNECTED intents?Android 模拟器可以接收 ACTION_POWER_CONNECTED 意图吗?
【发布时间】:2011-02-28 01:18:42
【问题描述】:

在我的应用程序中,我正在尝试像这样监听 ACTION_POWER_CONNECTED 意图:

    <service android:name=".myService">
        <intent-filter>
            <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
        </intent-filter>
    </service>

我认为我可以通过通过 telnet 向模拟器发送“power ac on”命令来测试这一点,但是,我的服务似乎没有收到意图。我可以使用这种方法接收 BATTERY_LOW 意图。

我注意到这条消息:http://groups.google.com/group/android-developers/msg/84e968734c51d50e 建议您无法使用模拟器对此进行测试,但它已经使用了几个月,而且其中的链接似乎已过时,而且我没有设备方便测试。

谁能确认?您是否能够使用来自 telnet 的命令接收此意图?谢谢。

【问题讨论】:

    标签: android emulation android-intent


    【解决方案1】:

    我能够确认这一点。您可以使用广播接收器获取 Power Connected 事件。

        <receiver android:name=".MyReceiver" android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    

    来自 telnet 的命令是:

        power ac on
    

    【讨论】:

    • +1 两个答案。 telnet localhost 5554,然后是 power ac on。或power ac off 断开连接。
    【解决方案2】:

    我也可以确认使用power ac on 广播这些意图可以在模拟器上运行。另外我想补充一点,您必须为模拟器选择正确的 telnet 端口。一开始我尝试了 adb telnet 端口,但它当然是模拟器实例之一(通常是 5554)。

    所以telnet localhost 5554 应该可以解决问题。该端口也显示在模拟器的标题栏中,或者您可以在 linux 下使用netstat -lntp |grep emulator 获取该端口。这里也是一个不错的howto

    【讨论】:

      猜你喜欢
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 2011-01-06
      • 1970-01-01
      相关资源
      最近更新 更多