is Charging Battery - Android Hardware

Android examples for Hardware:Battery

Description

is Charging Battery

Demo Code


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

import android.os.BatteryManager;

public class Main {
    private static Boolean isCharging(Context context) {
        IntentFilter ifilter = new IntentFilter(
                Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = context.registerReceiver(null, ifilter);
        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS,
                -1);/*from  www . j av a  2 s.com*/

        return status == BatteryManager.BATTERY_STATUS_CHARGING
                || status == BatteryManager.BATTERY_STATUS_FULL;
    }
}

Related Tutorials