android


Upload sensor data from Android device to remote host


I want to develop an Android application that satisfies the following specifications:
Record data from a sensor (for example the accelerometer) at an
approximate rate of 10-30 Hz.
Upload this raw data to a remote server (for example using TCP
sockets).
The user interface should be minimum, just a pair of buttons to start
or stop the recording and transmission of the data.
All the process should be unnoticeable for the user and keep working
when the screen goes off for several hours.
Battery life is not critical (it should last several hours).
Vision: I would like to analyse in quasi-real time the sensor measurements of a group of users without their intervention (apart from starting the application).
After some research, I could manage to perform these tasks separately and inefficiently. I've tried classes such as Service and IntentService, SensorEventListener, etc. I don't know if I should use Thread, Service or IntentService for each task. Specifically, I have serious problems to communicate them.
My questions:
What class(es) do you recommend to use in order to solve this
problem?
What task should be done on each of them?
If the tasks are performed in different entities (threads, services,
intentservices, etc.), how should I intercommunicate them (I'm
thinking about the recording and uploading tasks)?
I am asking for the best-practice structure to solve my problem. You do not need to go into details in terms of developing/coding the solution.
Thank you very much and feel free to ask if something is not clear enough.
David
UPDATE:
After some more research and thanks to DROIDcoder, I manage to design a skeleton for my app:
Main UI: Activity object presenting two buttons (start/stop) that
will launch a Service with the usual startService/stopService methods
Background: Service object
Awake when screen goes off: the service requests a power lock in onCreate() and releases the power lock in onDestroy(). Find more info here: https://developer.android.com/training/scheduling/wakelock.html#cpu
Log sensor values: implement SensorEventListener in the Service as usual
Upload sensor values to server: use AsyncTask in the service as described here: How to use AsyncTask
Data formatting and transmission: use GSON library + HttpClient as described here: How to send POST request in JSON using HTTPClient?
Testing: use the website http://www.jsontest.com/ to test the JSON queries
As this is only a proposition, I add it as an edition. I will post a detailed answer when the whole system works.
The questions remains: can you think about a better design for the application?
Thanks again!
here are my suggestion
Upload this raw data to a remote server
You can use JSON parsing for server communications. you will use AsynTask(Background Thread) for background data uploading
All the process should be unnoticeable for the user and keep working when the screen goes off for several hours.
You should use services for background long term processing
Finally what I have done:
Issue 1: record data from a sensor on the background for a long period of time.
Solved using the class Service to initialize the sensor and listen for callbacks.
Issue 2: communicate the Activity class holding the UI with the Service class.
Solved using the startService(Intent myMessage) method from the Activity class combined with a switch in the onStartCommand() method from the Service class to classify the message.
Issue 3: communicate the Service class with the Activity class.
Solved registering a custom BroadcastReceiver in the Activity and sending Intents from the Service. I've used it to update a progress bar (in the Activity) during the file uploading (in the Service). An exceptional tutorial can be found here.
Issue 4: upload data to a remote server.
Solved using AsyncTask inside the Service like in this site.

Related Links

Which is the charset for characters ́ ̂?
How to know which activity has invoked current activity?
Fullscreen activity always showing nav ui on interaction
Download files from server freezes app and loses connection
Trying to scroll up a scrollview in all apis
items don't appear directly in the action bar as action buttons
Can't import SQLite database
pass the spinner selected value to mysql using php from response in android
when Open notification to intent activity when app is closed on android
Robotium How to test with background Services like conversion?
How to sync Calender with an android app
Android ExoPlayer Playback speed very fast on Android 4.2 version
Show auto suggestion on search bar in android?
ksoap2 custom serialized response
Disable soft keyboard for an Edittext
Android Maps GPS outlier

Categories

HOME
oracle12c
twitter-bootstrap-3
checkstyle
apache-jena
angular-formly
zend-framework
graphics
nuget
google-cloud-functions
database-normalization
angularfire2
discrete-mathematics
arangodb
g++
dkim
startup
favicon
atlassian
do-while
screen-readers
digital-signature
apache2.4
ag
libigl
parcelable
roslyn
easeljs
displaytag
bringtofront
ceylon
postback
angularjs-material
installshield-le
openwhisk
pop3
navigator
roblox
swagger-php
tex
flatmap
jvmti
p4merge
apache-stanbol
mcustomscrollbar
doc
trigonometry
movilizer
uiimage
facebook-social-plugins
jboss-4.2.x
textsum
amq
objectscript
swingworker
reachability
webjars
i386
synonym
swizzling
findfirst
halcon
httpruntime.cache
ascii-art
atan2
iokit
include-guards
batik
typemock
linked-tables
botan
telepat
kubuntu
entity-framework-4.3
zxspectrum
procedural-programming
android-cookiemanager
uncaught-typeerror
alternate
conditionaltagsupport
getopt
mbunit
script#
rolify
nebula
cardreader
virtual-pc
apache-abdera
zope.interface
lambdaj
flex-mobile
jquery-tools
htdocs
entitydatasource
xui
photolibrary
metaweblog
office-2007
folding
escrow
technical-debt
ifilter
contentpresenter
pbcopy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App