6 Replies Latest reply on Jun 5, 2017 12:16 PM by bcalzadilla RSS
    bcalzadilla 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!