AWARE allows you to offload collected data to a remote server using JSON. We have included two utility classes: Http and Https. They allow insecure and secure data offloading, respectively. We  demonstrate how to send data from the accelerometer to a page hosted by you (e.g., YOUR_PAGE_URL) using POST and GET. Since Android 4.4, HTTP requests need to occur on a separate thread from the application thread. In other words, use the following code on an AsyncTask, Service or IntentService, just to name a few approaches.

Send insecurely data using HTTP POST

//Get the last 1000 records from accelerometer
Cursor accelerometer_data = getContentResolver().query(Accelerometer_Provider.Accelerometer_Data.CONTENT_URI, null, null, null, Accelerometer_Provider.Accelerometer_Data.TIMESTAMP + "DESC LIMIT 1000"); 
if( accelerometer_data != null && accelerometer_data.getCount() > 0 ) {
    Http http = new Http(getApplicationContext());
    Hashtable<String, String> postData = new Hashtable<>();
    postData.put("accelerometer_data", DatabaseHelper.cursorToString(accelerometer_data));
    http.dataPOST(YOUR_PAGE_URL, postData, false); //set to true if your server supports gzip compression
}
if( accelerometer_data != null && ! accelerometer_data.isClosed() ) accelerometer_data.close();

In this example, the data is sent as a JSON array with the last 1000 records of the accelerometer data to YOUR_PAGE_URL on the POST variable called accelerometer_data.

Send insecurely data using HTTP GET

//Get the last 1000 records from accelerometer
Cursor accelerometer_data = getContentResolver().query(Accelerometer_Provider.Accelerometer_Data.CONTENT_URI, null, null, null, Accelerometer_Provider.Accelerometer_Data.TIMESTAMP + "DESC LIMIT 1000");
if( accelerometer_data != null && accelerometer_data.getCount() > 0 ) {
    Http http = new Http(getApplicationContext());
    http.dataGET(YOUR_PAGE_URL + "?accelerometer_data="+ DatabaseHelper.cursorToString(accelerometer_data), false); //set to true if your server supports gzip compression
}
if( accelerometer_data != null && ! accelerometer_data.isClosed() ) accelerometer_data.close();

In this example, the data is sent as a JSON array with the last 1000 records of the accelerometer data to YOUR_PAGE_URL on the GET variable called accelerometer_data.

Send securely data using HTTPS POST

You need a copy of the public certificate (.crt) of the HTTPS server you are connecting to. See here how to export a certificate to use on your application.

//Get the last 1000 records from accelerometer
Cursor accelerometer_data = getContentResolver().query(Accelerometer_Provider.Accelerometer_Data.CONTENT_URI, null, null, null, Accelerometer_Provider.Accelerometer_Data.TIMESTAMP + "DESC LIMIT 1000");
if( accelerometer_data != null && accelerometer_data.getCount() > 0 ) {
    Https https = new Https(getApplicationContext(), getResources().openRawResource(R.raw.your_certificate)); //put your certificate in /res/raw/your_certificate.crt
    Hashtable<String, String> postData = new Hashtable<>();
    postData.put("accelerometer_data", DatabaseHelper.cursorToString(accelerometer_data));
    https.dataPOST(YOUR_PAGE_URL, postData, false); //set to true if your server supports gzip compression
}
if( accelerometer_data != null && ! accelerometer_data.isClosed() ) accelerometer_data.close();

In this example, the data is sent as a JSON array with the last 1000 records of the accelerometer data to YOUR_PAGE_URL on the POST variable called accelerometer_data.

Send securely data using HTTPS GET

You need a copy of the public certificate (.crt) of the HTTPS server you are connecting to. See here how to export a certificate to use on your application.

//Get the last 1000 records from accelerometer
Cursor accelerometer_data = getContentResolver().query(Accelerometer_Provider.Accelerometer_Data.CONTENT_URI, null, null, null, Accelerometer_Provider.Accelerometer_Data.TIMESTAMP + "DESC LIMIT 1000");
if( accelerometer_data != null && accelerometer_data.getCount() > 0 ) {
    Https https = new Https(getApplicationContext(), getResources().openRawResource(R.raw.your_certificate)); //put your certificate in /res/raw/your_certificate.crt
    https.dataGET(YOUR_PAGE_URL + "?accelerometer_data=" + DatabaseHelper.cursorToString(accelerometer_data), false); //set to true if your server supports gzip compression    
}
if( accelerometer_data != null && ! accelerometer_data.isClosed() ) accelerometer_data.close();

In this example, the data is sent as a JSON array with the last 1000 records of the accelerometer data to YOUR_PAGE_URL on the GET variable called accelerometer_data.

Remote data offloading