[SOLVED] I want to get multiple data from the ubidots using android app


#1

I want to get multiple data from the ubidots using android app


[SOLVED] Can i do arithmatic operation and casting on value[]
#2

Can you give more details about your question?

Are you creating an Android application and using our Java library?

Here is an example from their documentation:
http://ubidots.com/docs/devices/android.html#android-sdk

And another topic that was solved and had with a similar question


#3

How can i cast value[] into integer value


#4

The Value class has 3 methods:

  • getTimeStamp()
  • getValue()
  • getContext()

You can use the getValue() method to obtain the data in that particular Value, it will return a double type.

If you want to cast the double data type to an integer data type, just do:

int newValue = (int) values[0].getValue();

Where [0] is the position of the Value you want to access.


#5

Hi, this answer is very helpful, but I still have problem when I wrote this to get value from ubidots:

private class RecUbidots extends AsyncTask<Integer, Void, Void> {
    private final String API_KEY = "(my api key)";
    private final String VARIABLE_ID = "(the variable id)";
    @Override
    protected Void doInBackground(Integer... params) {
        ApiClient apiClient = new ApiClient(API_KEY);
        Variable RecVal = apiClient.getVariable(VARIABLE_ID);
        Value[] values = RecVal.getValues();
        int Val = (int)values[0].getValue();
        return null;
    }
}

So, I have two questions.

  1. Why I always get the value “0”. Also when I changed values[0] to other data positions, I only get 0. Of course the data of my variable is not only 0)
  2. How can I get the newest data point of my variable?

#6

Thanks, that helped me a lot too.