Majority of the builtin AWARE sensors have a column in the database for labeling data. The column is simply named ‘label’. Using broadcasts, instead of listening to broadcasts like in the ‘reading data’ tutorial, this time we are sending a broadcast to the sensor to change the label.
Sending the broadcast is simple. Basically what you are doing is send the broadcast with the proper ‘tag’ or topic, which depends on the sensor you want to set the label on, and then adding a broadcast extra with the label you want as a string. Then just send the broadcast.
The following code snippet changes the label for the accelerometer sensor.
Intent newLabel = new Intent(Accelerometer.ACTION_AWARE_ACCELEROMETER_LABEL); newLabel.putExtra(Accelerometer.EXTRA_LABEL, ”my new label for these data rows”); sendBroadcast(newLabel);
If you have debug messages set ‘on’ on the AWARE client, you will see the label change in your Android Studio logcat messages. If you are not seeing any change, make sure to rebuild your project. Another common simple mistake is putting the (static) label changes inside the plugin’s onCreate() method. The way AWARE and Android work together is that the onCreate() method only gets called once but the plugin might get shutdown by Android (if it takes up too much memory in the background, for instance) and then restarted by AWARE every 5 minutes. When AWARE restarts the plugin the onCreate() method no longer gets called. AWARE calls the onResume() method instead, so it’s a good idea to put any static label changes inside the onResume() method instead.