in my application, I'm trying to listen for the ACTION_POWER_CONNECTED intent like so:
<service android:name=".myService">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</service>
I assumed I would be able to test this by sending the emulator the "power ac on" command over telnet, however, my service doesn't seem to be receiving the intent. I'm able to receive the BATTERY_LOW intent using this method just fine.
I notice this message: http://groups.google.com/group/android-developers/msg/84e968734c51d50e suggests that you can't test this with the emulator, but its a few months old and the link in it seems to be out-of-date, and I don't hav开发者_高级运维e a device handy to test.
Can anyone confirm? Are you able to receive this intent using a command from telnet? Thanks.
I was able to confirm this. You can get the Power Connected event with a broadcast receiver.
<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>
The command from telnet would be:
power ac on
I too can confirm that broadcasting these intents with power ac on
works on the emulator. Also I'd like to add that you have to chose the right telnet port for the emulator. At first I tried the adb telnet port, but of course it's the one of the emulator instance (usually 5554).
So telnet localhost 5554
should do the trick. The port is also displayed in the title bar of the emulator or you can get the port under linux with netstat -lntp |grep emulator
. Here is also a good howto.
精彩评论