hii, i have some problem to get 2 data in android studio. i want get data soil and distance, but i just get data soil in my android app. And distance data not show how to fix it ?
this is code from android
private static final String SOIL_LEVEL = “Soil”;
private static final String DISTANCE_LEVEL= “Distanace”;
private TextView sensorSoil;
private TextView sensorDistance;
private BroadcastReceiver mSensorSoil = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int level = intent.getIntExtra(SOIL_LEVEL, 0);
sensorSoil.setText(Integer.toString(level) + "%");
new ApiUbidots().execute(level);
}
};
private BroadcastReceiver mSensorDistance = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int level = intent.getIntExtra(DISTANCE_LEVEL, 0);
sensorDistance.setText(Integer.toString(level) + "cm");
new ApiUbidots().execute(level);
}
};
@Override
protected void onStart() {
super.onStart();
registerReceiver(mSensorSoil, new IntentFilter());
registerReceiver(mSensorDistance, new IntentFilter());
}
@Override
protected void onStop() {
unregisterReceiver(mSensorSoil);
unregisterReceiver(mSensorDistance);
super.onStop();
}
public class ApiUbidots extends AsyncTask<Integer, Void, Void> {
private final String API_KEY = "your api";
private final String SOIL_ID = "id1";
private final String DISTANCE_ID="id2";
@Override
protected Void doInBackground(Integer... params) {
ApiClient apiClient = new ApiClient(API_KEY);
Variable soilLevel = apiClient.getVariable(SOIL_ID);
Variable distanceLevel= apiClient.getVariable(DISTANCE_ID);
soilLevel.saveValue(params[0]);
distanceLevel.saveValue(params[0]);
return null;
}
}