0

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!) Help 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"?

Community
  • 1
  • 1
Lork
  • 889
  • 3
  • 12
  • 24
  • which android version is your phone? – Blitz Oct 03 '11 at 10:54
  • 2.2 but during some test i have concluded that the bigger battery killer inside my app isn't data but is partial wake lock. I'll try to use alarm manager (i never used it before...) to avoid this problem...thanx! – Lork Oct 04 '11 at 06:42

3 Answers3

0

Since Android 1.5, the AlarmManagers 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.

Josef Pfleger
  • 74,165
  • 16
  • 97
  • 99
  • No i don't need it. My app need to be always wake up....But the answer to the main (title) question is .....? – Lork Oct 02 '11 at 14:25
0

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.

Blitz
  • 5,521
  • 3
  • 35
  • 53
  • Thanx LordT. I use GPRS because there is no others network here! (i live in mountain). 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!) Help me! – Lork Oct 02 '11 at 14:32
  • Ah, that very important info. Updated the question. – Blitz Oct 02 '11 at 14:33
0

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanx i have edited the question! Due to the new info: do you think that disable data connection between two upload may be save more battery? (sure that there is no dfference between GSM and GPRS? when the phone have Mobile data disable manually there isn't icon bar, but when you enable mobile data i get gprs icon onn status bar..) – Lork Oct 02 '11 at 14:39
  • @Lork: "do you think that disable data connection between two upload may be save more battery?" -- possibly, but it will make your actual I/O more complicated. The connection is unlikely to be re-established instantaenously, so you would have to wait to try to do the upload until after the connection is established, while also making sure Android will not terminate your process in the meantime. This feels to me like premature optimization, if your sole bit of testing is looking at an icon in the status bar. – CommonsWare Oct 02 '11 at 15:04
  • There is a difference between "re-establish the connection" and set "mobile data off". In fact the first is when you put down the entire connection (example airplane mode) but the second is equivalent to the manual operation (settings->wireless and ...->mobile net->active/disactive mobile data) and is instantaenously operation. This can be view also in logcat...and take less than 1 second. Anyway now my phone has somtings wrong because in the pas if i put it no sllep mode after a whole he automatically deactivate the mobile data...today it doesn't. – Lork Oct 02 '11 at 17:31
  • Only to make test: is there a way to use this code http://stackoverflow.com/questions/3644144/how-to-disable-mobile-data-on-android inside a service class as a function, without create a new one? – Lork Oct 02 '11 at 17:32