Skip to main content

ProductLookup

Product details returned by a UPC lookup. Look up a UPC with RecognizerClient; see Looking up a UPC. Added in 2.5.0.

Package: com.microblink.core

Declaration

data class ProductLookup @JvmOverloads constructor(
var upc: String? = null,
var name: String? = null,
var url: String? = null,
var brand: String? = null,
var rewarded: Boolean = false,
var brandParticipates: Boolean = false,
var message: String? = null,
) : Parcelable

Quick Reference​

Properties​

PropertyDescription
upcUPC of the product
nameProduct name
urlURL of the product image
brandBrand name
rewardedWhether the product participates in your rewards program
brandParticipatesWhether the product's brand participates in your rewards program
messageServer message, or the error when the lookup failed

Properties​

upc​

var upc: String?
// Java: getUpc() / setUpc(String)

UPC of the product.


name​

var name: String?
// Java: getName() / setName(String)

Product name.


url​

var url: String?
// Java: getUrl() / setUrl(String)

URL of the product image.


brand​

var brand: String?
// Java: getBrand() / setBrand(String)

Brand name.


rewarded​

var rewarded: Boolean
// Java: isRewarded() / setRewarded(boolean)

true if the product participates in your rewards program.

Default: false


brandParticipates​

var brandParticipates: Boolean
// Java: isBrandParticipates() / setBrandParticipates(boolean)

true if the product's brand participates in your rewards program.

Default: false


message​

var message: String?
// Java: getMessage() / setMessage(String)

Message returned by the server with the result. When the lookup fails because of a network or server error, it holds the error and the other properties keep their defaults.


Looking up a UPC​

RecognizerClient is in com.microblink (blinkreceipt-recognizer).

class RecognizerClient() {
@JvmOverloads
fun lookup(
upc: String,
cancellationToken: CancellationToken? = null, // com.google.android.gms.tasks.CancellationToken
): Task<ProductLookup> // com.google.android.gms.tasks.Task
}

lookup() runs the network request on Dispatchers.IO. The returned task never fails:

  • A network or server error, including a timeout, is reported in message.
  • A UPC the server does not know returns an empty ProductLookup (every property at its default).
  • Cancelling cancellationToken abandons the request and cancels the task. A token that is already cancelled returns a cancelled task without making a request.

Task and CancellationToken come from play-services-tasks, which blinkreceipt-recognizer exposes to your app. Kotlin callers can suspend on the task with kotlinx.coroutines.tasks.await(cancellation), which cancels the request when the coroutine is cancelled; add org.jetbrains.kotlinx:kotlinx-coroutines-play-services to your app for it.

import com.google.android.gms.tasks.CancellationTokenSource
import com.microblink.RecognizerClient
import kotlinx.coroutines.tasks.await

// Suspends; call from a coroutine. Cancelling the coroutine cancels the request.
val cancellation = CancellationTokenSource()
val product = RecognizerClient().lookup("012345678905", cancellation.token).await(cancellation)

if (product.message == null) {
showProduct(product.name, product.brand, product.rewarded)
}
note

com.microblink.RecognizerClient replaces com.microblink.barcode.RecognizerClient, which was removed with the barcode module. The unrelated com.microblink.ProductLookup interface from earlier versions is no longer public; the name now belongs to this class in com.microblink.core.