cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Newbie

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

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!

Tags (2)
7 REPLIES 7

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

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

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

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.

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

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

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

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

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

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

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

Hi, it doesn´'t work, I still do not get the initial value of the property

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

Any Success? I am looking for same. Please share.