[SOLVED] I want to get data from the ubidots using this http://ubidots.com/docs/devices/android.html


#1

i just made that code and its works. the challenge is i want to get the data from the ubidots and put it on the textView, what should i do and what to do. i need it the whole code in android studio so that i can study every detail. thank you :slight_smile:


#2

Hi @GoldenRatio! did you try the answer below? (http://community.ubidots.com/t/getting-data-from-ubidots-using-android-studio/222/2?u=hackmed)

If so, what was the output? where did you find a roadblock? This can help the community understand your case.

Now, once you have the value, modifying a textView in Android sounds like a task you should find in Android tutorials or forums.

Changing the Ubidots Android Example to get data

Original function:

    public class ApiUbidots extends AsyncTask<Integer, Void, Void> {
        private final String API_KEY = "our_api_key";
        private final String VARIABLE_ID = "our_variable_id";

    @Override
    protected Void doInBackground(Integer... params) {
        ApiClient apiClient = new ApiClient(API_KEY);
        Variable batteryLevel = apiClient.getVariable(VARIABLE_ID);

        batteryLevel.saveValue(params[0]);
        return null;
    }
}

New function:

public class ApiUbidots extends AsyncTask<Integer, Void, Value[]> {
    private final String API_KEY = "our_api_key";
    private final String VARIABLE_ID = "our_variable_id";

    @Override
    protected Values[] doInBackground(Integer... params) {
        ApiClient apiClient = new ApiClient(API_KEY);
        Variable batteryLevel = apiClient.getVariable(VARIABLE_ID);
        Value[] variableValues = batteryLevel.getValues();

        return variableValues;
    }

    @Override
    protected void onPostExecute(Value[] variableValues) {
        // Update your views here
    }
}

#4

yes i tried it, i only copy paste the code and change the API KEY and VARIABLE ID. I only see on my app is the battery level of the phone. and i send data to cloud using aduino to see the app if is retrieving but nothing change on the app. please help me on how to update views.


#5

A TextView can be updated using the method

setText(CharSequence text)

You can check the documentation of the TextViews in Android Developer site and this is a great tutorial on how to manipulate TextViews.

Android Developers: TextView Reference
Android4Beginners: How to modify textview


#6

Hey @GoldenRatio I’m not an Android or Java expert but I can draft an example using App Inventor (ai2.appinventor.mit.edu), would that help?


#7

yes that will be a big help, here is my account josetayo3@gmail.com. thank you guys :slight_smile:


#8

Here’s an App Inventor Example Code. The app reads the last value of a variable every second.

Designer View:

where:

Blocks View:

Here’s the AIA file for your to upload to your AI2 account GET_Ubidots.aia.zip (3.0 KB)


#9

can you please reupload the aia zip file for mitappinventor


#10

please reupload the aia zip file