当设备的电池电量不足时,我想关闭我的应用程序。 我在清单中添加了以下代码。如何检测电池电量低时:Android?
<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!!");
}
}
我正在上emulater应用和改变使用telnet电池电量。 它改变电池电量,但不显示任何烤面包或日志。
我在想什么? 任何帮助表示赞赏! 谢谢。
感谢您的回复。 我试过registerReceiver(myBatteryReceiverLow,新的IntentFilter(Intent.ACTION_BATTERY_LOW)); 但它不是工作压力太大:( – Aadi
你有没有洗过清单,并发送广播动作handly ACTION_BATTERY_LOW =“android.intent.action.BATTERY_LOW”; – Yahor10
我已经打扫清单 但什么是发送广播动作handly意思? 我没有在广播上工作太多..你能帮我吗? – Aadi