如何检测电池电量低时:安卓?
我想在设备的电池电量降低时关闭我的应用。我在清单中添加了以下代码。
<receiver android:name=".BatteryLevelReceiver"
<intent-filter>
<action android:name="android.intent.action.ACTION_BATTERY_LOW" />
<action android:name="android.intent.action.ACTION_BATTERY_OKAY" />
</intent-filter>
</receiver>
并在接收器中遵循以下代码
public class BatteryLevelReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "BAttery's dying!!", Toast.LENGTH_LONG).show();
Log.e("", "BATTERY LOW!!");
}
}
我正在模拟器上运行该应用程序,并使用telnet更改电池电量。它会更改电池电量,但不显示任何 Toast 或日志。
我错过了什么?任何帮助是值得赞赏的!