当设备的电池电量不足时,我想关闭我的应用程序。我在清单中添加了以下代码。
<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 更改电池电量。它会更改电池电量,但不显示任何吐司或日志。
我错过了什么?任何帮助表示赞赏!