Activity collection
Set Builder.userId to your stable player ID to enable tap-to-collect for collectible content authored in Graffity Console. The ID also scopes user-specific content requests.
import android.content.Context
import tech.graffity.android.arcloud.publicapi.*
class CollectionSession(
context: Context,
accessToken: String,
playerId: String
) : GraffityARCloudListener {
val sdk = GraffityARCloudSDK(
context,
GraffityARCloudConfiguration.Builder(accessToken)
.mode(GraffityARMode.ARContent)
.userId(playerId)
.build()
).also { it.listener = this }
override fun onContentCollected(
sdk: GraffityARCloudSDK,
contentId: String,
activity: GraffityARActivity
) {
println("Collected: $contentId")
println("Progress: ${activity.collectedContentIds.size}/${activity.maxCollectionSize}")
if (activity.isFinished) {
// Present your app's completion UI.
println("Finished activity: ${activity.id}")
}
}
suspend fun endSession() {
sdk.listener = null
sdk.shutdown()
}
}Retain the owner and host its SDK view or fragment as in the quick start. Without userId, player collection cannot be submitted. Ordinary content still needs a collection effect to become collectible.
Collection result
GraffityARActivity is a data class with read-only properties:
| Property | Type | Meaning |
|---|---|---|
id | String | Activity identifier. |
projectId | String | Project or campaign. |
playerId | String | Participating player. |
isFinished | Boolean | Completion status. |
collectedContentIds | List<String> | Collected content database IDs. |
maxCollectionSize | Int | Required collection size. |
bannerImageUrl | Uri? | Optional banner. |
collectionEmptyImageUrl | Uri? | Optional empty-slot image. |
collectionActiveImageUrl | Uri? | Optional filled-slot image. |
lastModified | Instant? | Last server modification. |
Use callbacks to update your app’s progress and completion UI. Collection works with default GraffityARTelemetry.Disabled.