I am creating an android gps tracking application and so far have my location uploaded to firebase using the Location Class:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference(path);
Location location = locationResult.getLastLocation();
if (location != null) {
//Save the location data to the database//
ref.setValue(location);
Log.d(TAG, "Location sent");
}
I can also get the battery level:
public float getBatteryLevel(){
Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if(level == -1 || scale == -1){
return 50.0f;
}
return ((float)level/(float)scale) * 100.0f;
}
What I would like to do is add the battery level field to the location so it is sent to firebase as one. Can I extend the 'Location' class to include a 'Battery' field and a method to update this field before sending?