i have followed the tutorial from ubidots on android app… i have been able to fetch the value form ubidots but i want to optimize the app according to my project… i want to get a temperature value. i have customized the code according to my understanding but it isnt working… here is my mainactivity.java
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import com.ubidots.ApiClient;
import com.ubidots.Value;
import com.ubidots.Variable;
public class MainActivity extends Activity {
private static final String TEMPERATURE = "temp";
private TextView temperature;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
temperature = (TextView) findViewById(R.id.batteryLevel);
}
@Override
protected void onStart() {
super.onStart();
temperature.setText("Temperature");
new ApiUbidots().execute();
// registerReceiver(temperature, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
@Override
protected void onStop() {
// unregisterReceiver(mBatteryReceiver);
super.onStop();
}
public class ApiUbidots extends AsyncTask<Integer, Void, Value[]> {
private final String API_KEY = "my_api_key";
private final String VARIABLE_ID = "var_id";
@Override
protected Value[] doInBackground(Integer... params) {
ApiClient apiClient = new ApiClient(API_KEY);
Variable batteryLevel = apiClient.getVariable(VARIABLE_ID);
Value[] variableValues = batteryLevel.getValues();
// hello=variableValues;
return variableValues;
}
@Override
protected void onPostExecute(Value[] variableValues) {
temperature.setText(Double.toString(variableValues[0].getValue()));
}
}
}