Skip to main content
1-Visitor
August 16, 2017
Solved

[Android SDK] How can I read load things from my server to a class?

  • August 16, 2017
  • 2 replies
  • 1357 views

Hello,

I installed android SDK, and so far, I could only modify data from the mobile application to the server.

Is it possible to first get a Thing from the server and load it in a class when defining it, for the data to be displayed in my mobile application?

Thank you

PA

    Best answer by jjohnson-21

    Please see the Android SDK Tutorial (https://developer.thingworx.com/resources/guides/thingworx-android-sdk-tutorial).

    It goes over retrieving data from the platform and storing it into variables. From there, you can easily put them into a class or use the calls to load a class directly.

    It also provides the Java code you would use plus explanations! For example, using getProperty("DeliveriesMade").getValue().getValue(); to retrieve a value that you would then cast. Or using the below calls:

    InfoTable result = client.readProperty(ThingworxEntityTypes.Things, ThingName, property, 10000);

    // Result is returned as an InfoTable, so we must extract the value. An InfoTable

    // is a collection of one or more rows. A row can have multiple fields. Each

    // field has a name and a base type. In this case, the field name is 'count' and

    // the base type is INTEGER, so we can use the getValue() helper.

    Integer count = (Integer) result.getFirstRow().getValue(property);

    // We can also access the value as a Primitive. This will work for all primitive types.

    IntegerPrimitive prim = (IntegerPrimitive) result.getFirstRow().getPrimitive(property);

    2 replies

    1-Visitor
    November 1, 2017

    Please see the Android SDK Tutorial (https://developer.thingworx.com/resources/guides/thingworx-android-sdk-tutorial).

    It goes over retrieving data from the platform and storing it into variables. From there, you can easily put them into a class or use the calls to load a class directly.

    It also provides the Java code you would use plus explanations! For example, using getProperty("DeliveriesMade").getValue().getValue(); to retrieve a value that you would then cast. Or using the below calls:

    InfoTable result = client.readProperty(ThingworxEntityTypes.Things, ThingName, property, 10000);

    // Result is returned as an InfoTable, so we must extract the value. An InfoTable

    // is a collection of one or more rows. A row can have multiple fields. Each

    // field has a name and a base type. In this case, the field name is 'count' and

    // the base type is INTEGER, so we can use the getValue() helper.

    Integer count = (Integer) result.getFirstRow().getValue(property);

    // We can also access the value as a Primitive. This will work for all primitive types.

    IntegerPrimitive prim = (IntegerPrimitive) result.getFirstRow().getPrimitive(property);

    planeyrie1-VisitorAuthor
    1-Visitor
    November 16, 2017

    Nice!

    Thanks a lot. I could do it as you said.