public class BatteryControllerImpl extends BroadcastReceiver implements BatteryController
BatteryController
. This controller monitors for battery
level change events that are broadcasted by the system.BroadcastReceiver.PendingResult
BatteryController.BatteryStateChangeCallback
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_LEVEL_TEST |
protected boolean |
mCharged |
protected boolean |
mCharging |
protected int |
mLevel |
protected boolean |
mPluggedIn |
protected boolean |
mPowerSave |
ACTION_DEMO, COMMAND_BARS, COMMAND_BATTERY, COMMAND_CLOCK, COMMAND_ENTER, COMMAND_EXIT, COMMAND_NETWORK, COMMAND_NOTIFICATIONS, COMMAND_STATUS, COMMAND_VOLUME, DEMO_MODE_ALLOWED, EXTRA_COMMAND
Constructor and Description |
---|
BatteryControllerImpl(Context context) |
Modifier and Type | Method and Description |
---|---|
void |
addStateChangedCallback(BatteryController.BatteryStateChangeCallback cb) |
void |
dispatchDemoCommand(String command,
Bundle args) |
void |
dump(FileDescriptor fd,
PrintWriter pw,
String[] args)
Prints the current state of the
BatteryController to the given PrintWriter . |
protected void |
fireBatteryLevelChanged() |
boolean |
isPowerSave()
Returns
true if the device is currently in power save mode. |
void |
onReceive(Context context,
Intent intent)
This method is called when the BroadcastReceiver is receiving an Intent
broadcast.
|
void |
removeStateChangedCallback(BatteryController.BatteryStateChangeCallback cb) |
void |
setPowerSaveMode(boolean powerSave)
Sets if the current device is in power save mode.
|
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getPendingResult, getResultCode, getResultData, getResultExtras, getSendingUserId, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setPendingResult, setResult, setResultCode, setResultData, setResultExtras
public static final String ACTION_LEVEL_TEST
protected int mLevel
protected boolean mPluggedIn
protected boolean mCharging
protected boolean mCharged
protected boolean mPowerSave
public BatteryControllerImpl(Context context)
public void dump(FileDescriptor fd, PrintWriter pw, String[] args)
BatteryController
BatteryController
to the given PrintWriter
.dump
in interface BatteryController
public void setPowerSaveMode(boolean powerSave)
BatteryController
setPowerSaveMode
in interface BatteryController
public void addStateChangedCallback(BatteryController.BatteryStateChangeCallback cb)
addStateChangedCallback
in interface BatteryController
public void removeStateChangedCallback(BatteryController.BatteryStateChangeCallback cb)
removeStateChangedCallback
in interface BatteryController
public void onReceive(Context context, Intent intent)
BroadcastReceiver
Context.registerReceiver(BroadcastReceiver,
IntentFilter, String, android.os.Handler)
. When it runs on the main
thread you should
never perform long-running operations in it (there is a timeout of
10 seconds that the system allows before considering the receiver to
be blocked and a candidate to be killed). You cannot launch a popup dialog
in your implementation of onReceive().
If this BroadcastReceiver was launched through a <receiver> tag,
then the object is no longer alive after returning from this
function. This means you should not perform any operations that
return a result to you asynchronously -- in particular, for interacting
with services, you should use
Context.startService(Intent)
instead of
Context.bindService(Intent, ServiceConnection, int)
. If you wish
to interact with a service that is already running, you can use
BroadcastReceiver.peekService(android.content.Context, android.content.Intent)
.
The Intent filters used in Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)
and in application manifests are not guaranteed to be exclusive. They
are hints to the operating system about how to find suitable recipients. It is
possible for senders to force delivery to specific recipients, bypassing filter
resolution. For this reason, onReceive()
implementations should respond only to known actions, ignoring any unexpected
Intents that they may receive.
onReceive
in class BroadcastReceiver
context
- The Context in which the receiver is running.intent
- The Intent being received.public boolean isPowerSave()
BatteryController
true
if the device is currently in power save mode.isPowerSave
in interface BatteryController
protected void fireBatteryLevelChanged()
public void dispatchDemoCommand(String command, Bundle args)
dispatchDemoCommand
in interface DemoMode