A thing will have two types of identifiers; a vendorThing ID (assigned by the thing vendor/developer) and thingID (assigned by Kii Cloud). You can retrieve the thing using one of these identifiers.
If you are developing on Android, you can save a thing as a Bundle. Later you can use the Bundle to restore the thing (e.g., when a new Activity is launched).
Retrieving and Saving Things
Retrieving with vendorThingID
The following sample code is retrieving a thing with its vendorThingID.
Android
In this sample code, we are saving the things in a Bundle so that it can be restored later. The thing instance is implementing the Parcelable, so you can save it into a Bundle. Plase also check Restoring Things
iOS
Swift:
Objective-C:
JavaScript
// Instantiate a thing by vendor thing ID.KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS",{success:function(thing){// Do something.},failure:function(error){// Handle the error.}});
Retrieving with thingID
The following sample code is retrieving a thing with its thingID.
Android
In this sample code, we are saving the things in a Bundle so that it can be restored later. The thing instance is implementing the Parcelable, so you can save it into a Bundle. Plase also check Restoring Things
iOS
Swift:
Objective-C:
JavaScript
// Instantiate a thing by thing ID.KiiThing.loadWithThingID("78924c8vy2984298vvc2",{success:function(thing){// Do something.},failure:function(error){// Handle the error.}});
Getting a list of things owned by the currently logged-in user
This sample code is for getting a list of things owned by the currently logged-in user or the groups of which the user is a member. You can filter the results by thing type with a method or a property, for example, the setThingType() method of the KiiThingQuery class for Java.
Android
For processing the query result, see Querying KiiObjects. Perform pagination as required.
iOS
Swift:
Objective-C:
JavaScript
// Get a list of groups that the current user is a member of.KiiUser.getCurrentUser().memberOfGroups({success:function(user,groupList){// Create a query for things owned by the current user or the groups that the current user is a member of.varquery=KiiThingQuery.thingQuery(user,groupList);// Query things.KiiThing.executeQuery(query,{success:function(result){varresultSet=result.getResult();for(vari=0;i<resultSet.length;i++){varthing=resultSet[i];// Do something.}if(result.hasNext()){// Get the next page of the result.result.getNextResult({success:function(result){// Handle the next page of the result.varresultSet=result.getResult();},failure:function(err){// Handle the error.}});}},failure:function(err){// Handle the error.}});},failure:function(theUser,errorString){// Handle the error.}});
Refreshing a thing
The following sample code refreshes a KiiThing instance with the latest thing information from the server.
A KiiThing instance created with the loadWithVendorThingID() method or the loadWithThingID() method already holds the latest information and does not need to be refreshed.
Android
iOS
Swift:
Objective-C:
JavaScript
// Instantiate a thing.varthing=...;// Refresh the thing.thing.refresh({success:function(thing){// Do something.},failure:function(error){// Handle the error.}});
Restoring Things (Android only)
The next sample code is restoring a thing from a Bundle and updating it with the latest information on Kii Cloud.
Android
Here is the basic steps:
Restore an instance of Thing from the Bundle.
Execute the refresh method to get the latest thing information from Kii Cloud.