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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

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

planeyrie
1-Visitor

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

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

ACCEPTED SOLUTION

Accepted Solutions

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);

View solution in original post

2 REPLIES 2

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);

Nice!

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

Announcements


Top Tags