It will be documented in Eclair.

On Sun, Sep 20, 2009 at 11:22 PM, Walles <johan.wal...@gmail.com> wrote:

>
> Is this documented anywhere?  I looked here...
> http://developer.android.com/reference/android/os/BatteryManager.html
>
> ... but AFAICS there's nothing about 0 meaning "unplugged".
>
> What you're suggesting *is* what I'm after, but I'm unwilling to use
> undocumented API features since they risk disappearing without notice.
>
>  Regards //Johan
>
> On 19 Sep, 22:29, Dianne Hackborn <hack...@android.com> wrote:
> > What do you mean by "in use"?  You can find out whether you are attached
> to
> > a power source with the "plugged" field (0 means not plugged in / on
> > battery, non-zero is the power source), which is generally what things
> use
> > to determine whether the device is plugged in (so it is okay to do more
> > power drawing operations).
> >
> >
> >
> > On Sat, Sep 19, 2009 at 12:42 PM, Walles <johan.wal...@gmail.com> wrote:
> >
> > > Thanks Mark, that was the hint I needed.
> >
> > > What I really wanted to know was whether or not the battery was
> > > currently in use, and for anybody else following this thread, here's
> > > the method I came up with:
> >
> > > "
> > >    /**
> > >     * Is the battery currently discharging?
> > >     *
> > >     * @return True if our battery is discharging.  False otherwise.
> > >     */
> > >    private boolean isDischarging() {
> > >        // Contact the battery manager
> > >        Intent batteryIntent =
> > >            registerReceiver(null, new IntentFilter
> > > (Intent.ACTION_BATTERY_CHANGED));
> > >        if (batteryIntent == null) {
> > >            Log.w(DrainOMeter.LOGGING_TAG,
> > >                  "Failed to talk to the battery manager, assuming
> > > we're on battery power");
> > >            return true;
> > >        }
> >
> > >        // Ask about battery charging status
> > >        int batteryStatus = BatteryManager.BATTERY_STATUS_UNKNOWN;
> > >        if (batteryIntent != null) {
> > >            batteryStatus =
> > >                batteryIntent.getIntExtra("status",
> >
> > > BatteryManager.BATTERY_STATUS_UNKNOWN);
> > >        }
> > >        if (batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
> > >            Log.w(DrainOMeter.LOGGING_TAG,
> > >                  "Failed to get battery charging status, assuming
> > > we're on battery power");
> > >            return true;
> > >        }
> >
> > >        return batteryStatus ==
> > > BatteryManager.BATTERY_STATUS_DISCHARGING;
> > >    }
> > > "
> >
> > >  Cheers //Johan
> >
> > > On 18 Sep, 11:54, Mark Murphy <mmur...@commonsware.com> wrote:
> > > > Walles wrote:
> > > > > I want to know if my device is currently charging.
> >
> > > > > How do I find that out?  I've been looking a bit at the Intents
> API,
> > > > > but AFAIU I can just subscribe to events from there, and a
> > > > > subscription is not what I'm after.  And even if I *did* want
> updates,
> > > > > I'd still need to know the initial state.
> >
> > > > > I just want to ask a one-shot "are we charging" question.  How can
> I
> > > > > do that?
> >
> > > > Register for the broadcast Intent with a null receiver. If you get a
> > > > non-null return value, then that return value is an Intent from the
> last
> > > > "sticky broadcast" matching your supplied IntentFilter. I believe the
> > > > battery updates are such a sticky broadcast. By passing null for the
> > > > receiver, you do not actually register a receiver and so do not need
> to
> > > > unregister anything later.
> >
> > > > For more instructions on this, look up registerReceiver() in the
> Context
> > > > class (which is a base class for Activity, Service, etc.).
> >
> > > > --
> > > > Mark Murphy (a Commons Guy)http://commonsware.com|
> > >http://twitter.com/commonsguy
> >
> > > > _The Busy Coder's Guide to *Advanced* Android Development_
> > > > Version 1.1 Available!
> >
> > --
> > Dianne Hackborn
> > Android framework engineer
> > hack...@android.com
> >
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support, and so won't reply to such e-mails.  All such
> > questions should be posted on public forums, where I and others can see
> and
> > answer them.
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to