Pulling Multiple Variables

I’m trying to pull multiple variables at once on an Android app. This works but is there better approach to this?

@Override
            public Map<String, String> callApi(@NonNull ParticleCloud ParticleCloud) throws ParticleCloudException, IOException {
                ParticleDevice device = ParticleCloud.getDevice(getIntent().getStringExtra(ARG_DEVICEID));



                Map<String, String> returnVals = new ArrayMap<>();
                String value;


                for (String var : new String[]{"V1", "V2", "V3", "V4", "V5"}) {
                    try {
                        value = device.getStringVariable(var);
                        returnVals.put(var, value);

                    } catch (ParticleDevice.VariableDoesNotExistException e) {
                        Toaster.l(VariablesActivity.this, "Error reading variable " + var);

                    }
                }
                return returnVals;
            }

@oraclerouter, I don’t believe there is anything you can do on the Android side but with the latest DeviceOS v1.5.0, you can now have calculated Cloud variables. On the device side, using a single variable, you could call a function which prepares a JSON string that contains all your variables/values and is returned as a single String to the variable request. On the Android side you can then parse the JSON to get all your values.

3 Likes

Got it. Thanks!

1 Like