Skip to main content
1-Visitor
May 31, 2017
Question

How to get the current value of a property when I start my Android Application

  • May 31, 2017
  • 2 replies
  • 4216 views

Good afternoon experts, I need to get the current value of a property (type NUMBER) when I start my application developed in Android and I can't find the way to do it.

Example: the value of the property  in Thingworx of a remote thing is 30 and I need to load in my application as a Double variable , I have tried with :

try {

                           sensor1 = new SteamThing("sensor1", "sensor1", client);

                            sensor1.addPropertyChangeListener(new VirtualThingPropertyChangeListener() {

                                @Override

                                public void propertyChangeEventReceived(final VirtualThingPropertyChangeEvent evt) {

                                    final String propertyName = evt.getProperty().getPropertyDefinition().getName();

                                    runOnUiThread(new Runnable() {

                                        @Override

                                        public void run() {

                                    

                                            DecimalFormat df = new DecimalFormat("#.##");

                                            if (propertyName.equals("PropertyX")) {

                                                propertyValue = (Double) evt.getPrimitiveValue().getValue();

                                                textview.setText(df.format(propertyValue));                                                                               

                                            }

                                            runOnUiThread(new Runnable() {

                                          

                                            });

                                        }

                                    });

                                }

                            });

                            connect(new VirtualThing[]{sensor1});

                        } catch (Exception e) {

                            Log.e(TAG, "Failed to initalize with error.", e);

                            onConnectionFailed("Failed to initalize with error : " + e.getMessage());

                        }

unsuccessfully,I use this to put in the onConnectionEstablished method the initial value when connecting the app

How else can I do it, thanks!

2 replies

5-Regular Member
June 1, 2017

Benyoced, just to confirm are you looking to push the property value from the ThingWorx to your Android Application or vice versa?

1-Visitor
June 1, 2017

Hi Sushant thx for the reply, its right I need to get the current value from Thingworx to my Android Application

1-Visitor
June 1, 2017

Sushant Pandey​ he is trying to push the value of a remote thing from TWX server to android application by putting in OnConnectionEstablished() method.

This is failing as the connection is failing .Please make sure connection works and it will work.

1-Visitor
June 1, 2017

Hi Ravi thx for the reply ,actually the connection works correctly but until the value changes in the processScanRequest() method .. I can get the value of the property, but I need it when the application starts

1-Visitor
June 2, 2017

You need to call processScanRequest once from the block where application is starting . Are you not able to call this method from initialization block?