Skip to content

Handle Json Content

NearIT allows you to receive JSON data as a recipe "What". To handle JSONs from the NearIT content Intent use this code:

if (NearUtils.carriesNearItContent(intent)) {
    val handled = NearITUIBindings.onNewIntent(this, intent)
    if(!handled) {
        val json = NearUtils.getCustomJson(intent)
        json?.content // json as an HashMap
    }
} else {
    // Intent was not carrying NearIT in-app content
}
if (NearUtils.carriesNearItContent(intent)) {
    boolean handled = NearITUIBindings.onNewIntent(this, intent);
    if (!handled) {
        CustomJSON json = NearUtils.getCustomJson(intent);
        json.content // json as an HashMap
    }
} else {
    // Intent was not carrying NearIT in-app content
}

You can also extract the CustomJson objects from a Parcelable instance, if you are manually handling ranging content.

If you wish to also fetch the trackingInfo object connected to the custom JSON content, use this method:

val trackingInfo = NearUtils.getTrackingInfo(intent)
TrackingInfo trackingInfo = NearUtils.getTrackingInfo(intent);