I'm developing an app that use Mobile Data connection (always GPRS) to upload in a loop each 5 minutes 300 kb of data. Between two upload i see that the data connection remains up (gprs logo on status bar) even if there aren't data transferring....
In this time (between two upload) the battery is used by the Mobile Data connection? Do you think that i should use this method to disable and enable connection between uploads to save the batterylife or is not helpfull?
If is it so...how can i use that code in my Service Class such as a function, without create a new class? THanx from a noob!
EDIT
The app is for my personal use and the app have the entire control of phone (the phone is alone and it doesn't interact with the user). So i can sto all data connection...but i can't use that code as i want (as a function!) H开发者_JS百科elp me!
EDIT 2
Anyway i'm able to enable and disable "airplane mode", but the reconnection require minim 13-14 seconds. May be this help to save battery in the "dead time"?
I'm developing an app that use Mobile Data connection (always GPRS) to upload in a loop each 5 minutes 300 kb of data.
You are using whatever the user's chosen data connection is. You can elect to skip doing the work on WiFi if you want, though I am not quite sure why.
In this time (between two upload) the battery is used by the Mobile Data connection?
The GSM or CDMA radio is always consuming battery. It consumes more during active data transfer, but it is always powered on (except when the device is in airplane mode).
Do you think that i should use this method to disable and enable connection between uploads to save the batterylife or is not helpfull?
Only if the only person who will ever run the application is you, you are running an Android 2.2 device (or older), and you don't mind messing up your phone.
The code you link to is pathetic -- it might break on some devices and might break in the future, since it is bypassing the SDK. Moreover, if it is not your phone, I am not quite certain why you think you have the right to foul up other people's devices. And, to top it off, you can no longer hold the permission necessary to use that hack, as of Android 2.3.
Since Android 1.5, the AlarmManager
s supports what is known as inexact repeating (setInexactRepeating
). It's basically a mechanism that allows to minimize the number of times the phone has to wake up for data by collecting the desired intervals from all applications on the device and ensuring that they all communicate at the same time.
Five minutes is pretty frequent though, maybe you can reduce it to 15 or 30 minutes, that will save a lot of battery.
GPRS costs a bit of battery, but generally, most phones are on "always on" data anyway. Other things that are really draining the battery are wake-locks. Are you keeping any of those? Why is it GPRS and not UTMS, for another matter? For the link you provided, that's a method to turn on mobile data usage for all apps. that's something you really don't want to do, as your users will be quite unhappy. There might be specific cases, (restricted deployment to tightly controlled handsets) were this makes sense, but overall, it won't matter.
Btw, in your android settings (Settings->System->Battery) you can find out how much your app is draining the battery.
[edit] in the case you describe, the best thing would be to really turn of the mobile data usage while you're not using it. But this will be rather tricky (without rooting your phone, i'm not even sure it's possible) and it'll take you a long time. Make sure you will really need that extrac percentage of juice.
As said in the post you linked, you'll need to have an Android Version <2.3 (up to 2.2) and the MODIFY_PHONE_STATE Permission to disable network. It's not possible on Gingerbread.
精彩评论