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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

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

bcalzadilla
1-Visitor

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!

7 REPLIES 7
supandey
19-Tanzanite
(To:bcalzadilla)

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

Hi Sushant thx for the reply, its right I need to get the current value from Thingworx to 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.

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

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

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

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

Announcements


Top Tags