Thank you, one last issue that I'm having, you said to get the battery
level to call registerReceiver with a null broadcast receiver, but
when I try the following code I get a nullpointerexception:
int rawlevel = registerReceiver(null,
batteryLevelFilter).getIntExtra("level", -1);
I'm not sure if thats right or not. When I was running a broadcast
receiver it grabbed the context and the code was as such:
int rawlevel = intent.getIntExtra("level", -1);
which worked but since I no longer use the broadcast receiver to grab
the intent I can't seem to figure out how to get it into a manageable
variable.
On Feb 3, 5:21 pm, Kostya Vasilyev <[email protected]> wrote:
> AppWidgetProvider *is* a broadcast receiver, so you can handle your alarm
> actions right there.
>
> Some broadcasts can't be received by declaring intent filters in the
> manifest, I believe battery state is one of those.
>
> No such limitation with your own alarm action, though, so there isn't a
> chicken and egg (= service and receiver) issue here, as for the battery
> broadcast.
>
> --
> Kostya Vasilyev --http://kmansoft.wordpress.com
> 04.02.2011 1:57 пользователь "Jeffrey" <[email protected]> написал:
>
>
>
>
>
>
>
> > One question on AlarmManager, the examples I'm seeing all say to set
> > up a broadcast receiver, but wouldn't that defeat the purpose using
> > alarmmanager to prevent running a BroadcastReceiver in a service? Or
> > is the AppWidgetProvider class able to receive the broadcast?
>
> > On Feb 3, 4:21 pm, Jeffrey <[email protected]> wrote:
> >> Wow, thank you! Now I guess I need to look up a tutorial on using the
> >> AlarmManager.
>
> >> On Feb 3, 7:46 am, Mark Murphy <[email protected]> wrote:
>
> >> > On Wed, Feb 2, 2011 at 9:57 PM, Jeffrey <[email protected]>
> wrote:
> >> > > I've got a battery widget I'm working on and I have a broadcast
> >> > > receiver for when the battery status changes, but I don't know where
> >> > > it needs to go. I tried putting it in the Configuration activity, but
> >> > > I keep getting this error:
>
> >> > > Activity com.android.blah has leaked IntentReceiver com.android.blah
> >> > > $2@43758c58 that was originally registered here. Are you missing a
> >> > > call to unregisterReceiver()?
>
> >> > > Please let me know what I'm doing wrong, I'm pretty new to broadcast
> >> > > receivers, so if I'm missing something basic please let me know.
>
> >> > I wouldn't use a broadcast receiver in this case. That would require
> >> > you to keep a service running 24x7, to host the receiver, and that is
> >> > bad for business.
>
> >> > Rather, just check the battery level periodically:
>
> >> > - via updatePeriodMillis in your metadata, or
> >> > - via AlarmManager, if the 30-minute minimum for updatePeriodMillis
> >> > will be too long (probably would be, in this case)
>
> >> > To check the battery level, call registerReceiver() with the
> >> > ACTION_BATTERY_CHANGED IntentFilter, but a null BroadcastReceiver. The
> >> > Intent that is returned to you will be the last-broadcast battery
> >> > change Intent, from which you can get the last-known battery level.
>
> >> > You can even let the user configure the polling period, to balance
> >> > between accuracy and battery consumption by the battery app widget.
>
> >> > --
> >> > Mark Murphy (a Commons Guy)http://commonsware.com|
>
> http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
>
>
>
>
>
>
>
>
> >> > Android Training in London:http://bit.ly/smand1andhttp://bit.ly/smand2
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<android-developers%2Bunsubs
> > [email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en