相关疑难解决方法(0)

如何检测电池电量低: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>
Run Code Online (Sandbox Code Playgroud)

并在接收器中的代码

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!!");
    }
}
Run Code Online (Sandbox Code Playgroud)

我在emulater上运行应用程序并使用telnet更改电池电量.它会改变电池电量但不显示任何烤面包或日志.

我错过了什么?任何帮助表示赞赏!谢谢.

java android

12
推荐指数
3
解决办法
2万
查看次数

标签 统计

android ×1

java ×1