Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best method for background uploader in Android

Tags:

android

Problem:

I want to write a process that will allow a user to take photos with the device and for those photos to then be uploaded to some listener in the cloud. The user should not have to do anything to initiate the upload, a background listener would just watch the folder and as long as it finds files in it it would upload them and delete them.

Two problems: 1) how to keep the program running in the background even after the user is no longer taking pictures (and if they reboot the device for it to wake up and finish the uploads, if any remain)

2) assuming the connection is spotty (as it always is) how to verify that a given image has completed its upload, and if not, to resubmit it.

I don't need any code examples, I just would like opinions on the best strategy to get this implemented.

I was going to use Apache commons and just do an upload to a PHP, but am not sure what sort of error checking exists to take into account a connection drop mid file.

TIA.

like image 687
Yevgeny Simkin Avatar asked Jan 14 '11 19:01

Yevgeny Simkin


2 Answers

Having essentially written this application several times on several platforms, I can tell you that it's not a trivial endeavor. To tackle the first problem, you can create a Service that sits in the background and performs your uploads. In order for it to start up automatically, you can declare that it receives the intent android.intent.action.BOOT_COMPLETED in your manifest (you'll need the permission android.permission.RECEIVE_BOOT_COMPLETED in order to make use of that). If you're going to listen for stuff written out by the standard camera app, you can use registerContentObserver to listen for new stuff - beware, phones can have more than one place they stash photos!

For the second problem, have your webservice return information regarding the completion of the upload which your client can use to decide on retries.

like image 109
jjb Avatar answered Oct 22 '22 04:10

jjb


I want to write a process that will allow a user to take photos with the device and for those photos to then be uploaded to some listener in the cloud.

Please either initiate the picture-taking yourself (so you know when it is time to upload) or create an ACTION_SEND Activity to plug into the camera app's Share option, so the user can upload that way.

The user should not have to do anything to initiate the upload, a background listener would just watch the folder and as long as it finds files in it it would upload them and delete them.

Please don't.

A major complaint among Android users are apps written using this sort of technique -- some "background listener" that is taking up RAM and delivering no value 99.999% of the time. The core Android team has been forced to modify the OS to prevent developers from screwing up users' phones this way. Newer versions of Android will terminate your "background listener" after a while. Users may terminate your "background listener" sooner than that, using a "task killer" or the Manage Services screen in the Settings app.

Please either initiate the picture-taking yourself (so you know when it is time to upload) or create an ACTION_SEND Activity to plug into the camera app's Share option, so the user can upload that way.

like image 4
CommonsWare Avatar answered Oct 22 '22 04:10

CommonsWare