is Charging Or Full - Android Hardware

Android examples for Hardware:Battery

Description

is Charging Or Full

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;

public class Main {
    public static boolean isChargingOrFull(Context context) {
        IntentFilter intentFilter = new IntentFilter(
                Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = context.registerReceiver(null, intentFilter);
        return isChargingOrFull(batteryStatus);
    }//  www . j a  va 2 s  . com

    public static boolean isChargingOrFull(Intent batteryStatus) {
        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS,
                -1);
        return status == BatteryManager.BATTERY_STATUS_CHARGING
                || status == BatteryManager.BATTERY_STATUS_FULL;
    }
}

Related Tutorials