【问题标题】:getting realtime data from ubidots to android app从 ubidots 获取实时数据到 android 应用程序
【发布时间】:2021-08-28 01:47:41
【问题描述】:

我正在做 ecg 监控 android 应用程序的项目,所以我需要从 ubidots 获取实时数据,当我运行应用程序时我设法获取最新的变量值,但不是所有将不断更新的新值。所以,我需要有助于在我的应用中获取实时数据,因此我的应用应该在 ubidots 变量中更新时获取数据。

这是我获取变量的代码:

public class MainActivity extends Activity {
private TextView ecgLevel;
String variableValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ecgLevel = (TextView) findViewById(R.id.ecg);
ApiUbidots getApi = new ApiUbidots();
getApi.execute();
}
class ApiUbidots extends AsyncTask<Integer, Void, Value[]> {
private final String API_KEY = “";
private final String VARIABLE_ID = "”;
@Override
protected Value[] doInBackground(Integer... params) {
    ApiClient apiClient = new ApiClient(API_KEY);
    Variable ecgLevel = apiClient.getVariable(VARIABLE_ID);
    Value[] variableValues = ecgLevel.getValues();
    return variableValues;
}
@Override
protected void onPostExecute(Value[] variableValues) {
    double varValue = variableValues[0].getValue();
    variableValue = (String.valueOf(varValue));
    ecgLevel.setText(variableValue);
}
}
}```

【问题讨论】:

    标签: java android iot


    【解决方案1】:

    获取最新变量后使用Retrofit 访问API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-02
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 2014-12-02
      相关资源
      最近更新 更多