Based on examples I managed already to retrieve data of one variable from Ubidots, here weight. However, I need to retrieve about 10 Variables from an Ubidots datasource.
Since I do have zero experience with Java programming, I would really appreciate if someone could adapt below single variable example to a multiple variables example.
package de.httpName.temp;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.ubidots.*;
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
new ApiUbidots().execute(15);
}
@Override protected void onStart() { super.onStart(); } @Override protected void onStop() { super.onStop(); } public class ApiUbidots extends AsyncTask<Integer, Void, com.ubidots.Value[]> { private final String API_KEY = "a23234234234"; private final String VARIABLE_ID = "b24234234234";
@Override protected com.ubidots.Value[] doInBackground(Integer... params) { ApiClient apiClient = new ApiClient(API_KEY);
Variable weight = apiClient.getVariable(VARIABLE_ID); com.ubidots.Value[] variableValues = weight.getValues();
return variableValues; } @Override protected void onPostExecute(com.ubidots.Value[] variableValues) {
TextView textViewW = (TextView) findViewById(R.id.weight_val); TextView textViewT = (TextView) findViewById(R.id.weight); Double variableValueW = variableValues[0].getValue(); textViewW.setText(String.valueOf(String.format("%.3f",variableValueW/1000))+" kg");
Long variableValueT = variableValues[0].getTimestamp(); String date = new java.text.SimpleDateFormat("dd. MMM yyyy HH:mm").format(new java.util.Date (variableValueT)); textViewT.setText(String.valueOf(date)); } }
}