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

How to get Button's Value clicked from other activity
Android Refreshing Fragment View after AsyncTask
Android app forcequit while viewing database
Shared Preferences available to all activites
Under Android NDK, can a native window be created without Java calls to retrieve the surface?
How to execute a query with IF and ELSE in Android sqlite?
Connecting Android device for debugging
Android Google Analytics SDK show “SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length”
Soft keyboard in webview - no “next” button to tab between input fields
Pause activity and go back to previous activity
pass a String to a class which extends PhoneStateListener
Listview Content Email
map application stops unexpectedly
Android set View visibility programmatically based on screen size
Cursor returning null for rawquery
how to include resource file in distributed jar file?

Categories

HOME
sonarqube
cygwin
microsoftgraph
facebook-oauth
telegram
sh
r-googlesheets
javacc
rom
webix
elasticsearch-5
mxgraph
intercom
dreamweaver
jersey-1.0
smartclient
identity-management
jmp
cfml
gulp-watch
ios10.2
inno-download-plugin
flask-sqlalchemy
pic32
flooding
underscore.js
linked-data
complex-numbers
cognos-bi
simplecv
card.io
hard-drive
slacktextviewcontroller
wurfl
xcode7.3
ideascript
projects-and-solutions
odroid
chef-solo
preloader
subclipse
clang++
user-defined-fields
semantic-logging
boxing
ngmaterial
skin
libjpeg
mach-o
bootstrap-tags-input
sandcastle
choice
docpad
mapxtreme
lrs
vulcanize
greatest-n-per-group
mongodb-php
vorpal.js
kango-framework
aurora
sklearn-pandas
fuzzywuzzy
nio2
phpgrid
character-replacement
fiware-monitoring
poppler
dock
pax-exam
haskell-warp
wso2greg
jquery-forms-plugin
exceldatareader
mass-assignment
rapidsvn
mdichild
malformedurlexception
memset
android-framework
windows-embedded-standard
spring-3
kendo-dataviz
dtmf
scringo
nevron
faye
jdb
agility.js
promotion-code
tournament
multiplatform
aspmenu
tabpanel
cuda.net
java1.4
information-management
online-storage

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App