Auto-Scrape
The automated e-receipt scrape is a host-owned client that schedules a periodic background scrape of the user's linked Gmail IMAP accounts. Once you start it, the SDK schedules a periodic WorkManager job that queues the same remote scrape as ImapClient.remoteMessages(...) for every eligible linked account and delivers each account's JobResults through the callbacks you pass to begin(...). The receipts themselves are scraped and parsed server-side and posted to your configured client endpoint — the callbacks carry the job handle (id, success, status code, message), not scan results.
The schedule follows the signed-in state: the job exists only while an eligible Gmail account is linked — it starts when such an account signs in (with the client started) and is cancelled when the last one signs out — and all scheduling runs under a single unique work name, so at most one background job can ever be ticking.
Starting the client represents the user's opt-in — it is off until begin(...) is called — and its opt-in state lives in memory only. The host owns the instance, so re-create it and call begin(...) at launch (for example in Application.onCreate()), before any scheduled run fires.
Package: com.microblink.digital
Declaration
class AutoScrapeClient(context: Context) : Closeable
The host creates and owns the AutoScrapeClient, passes its result and error callbacks straight into begin(...), and closes it when done.
Quick Reference
Constructor
| Constructor | Description |
|---|---|
AutoScrapeClient(context) | Creates a client bound to the application context |
Properties
| Property | Description |
|---|---|
intervalHours | The scrape cadence in hours (minimum 12, default 24, no upper cap) |
overrideEndpoint | Optional override for the endpoint automated results are POSTed to |
overrideDateTime | Optional scrape date-cutoff override, in epoch milliseconds |
countryCode | Optional ISO 2-character country code hint for parsing |
Methods
| Method | Description |
|---|---|
begin(success, failure) | Starts the periodic scrape and subscribes the result/error callbacks |
cancel() | Cancels the periodic scrape and unsubscribes the callbacks |
close() | Releases the client — cancels the scrape and the callbacks |
Constructor
AutoScrapeClient(context)
class AutoScrapeClient(context: Context) : Closeable
Creates an auto-scrape client. The application context is retained from context, so an Activity or Application context is fine. The client is idle until begin(...) is called.
Properties
intervalHours
var intervalHours: Int
The scrape cadence in hours — the override for the default 24 hour refresh. The 12 hour minimum is the only limitation: values below it (including zero and negatives) fall back to 12, and anything at or above it is used as-is with no upper cap. Changing it while the client is running reschedules the periodic work so the new cadence takes effect immediately; otherwise the value applies the next time the client is started from a cancelled state. Set it before begin(...), or update it while running to reschedule.
overrideEndpoint
var overrideEndpoint: String?
Optional override for the endpoint the backend POSTs automated-scrape results to — the auto-scrape counterpart of the manual client's overrideEndpoint. null (the default) keeps the client endpoint configured server side. Applied to every scheduled run; changing it while running re-applies to the schedule immediately.
overrideDateTime
var overrideDateTime: Long?
Optional date-cutoff override for the automated scrape, in epoch milliseconds — the auto-scrape counterpart of the manual client's overrideDateTime. null (the default) keeps the backend's own cutoff. Applied to every scheduled run; changing it while running re-applies immediately.
countryCode
var countryCode: String?
Optional ISO 2-character country code hint to improve parsing of automated-scrape results — the auto-scrape counterpart of the manual client's countryCode. null (the default) keeps the SDK default (US). Applied to every scheduled run; changing it while running re-applies immediately.
Methods
begin(success, failure)
fun begin(
success: (credentials: Credentials.Password, result: JobResults) -> Unit,
failure: (throwable: Throwable) -> Unit,
)
Starts the automated scrape and subscribes success / failure to receive per-account job results on a background thread — the same parameters as the manual ImapClient.remoteMessages(callback) path (JobResultsCallback): the account's credentials plus the JobResults (job id, success flag, status code, message). The periodic work is scheduled only once an eligible Gmail account is actually linked: with none present the client stays armed and the schedule starts on sign-in (and is cancelled again on sign-out of the last one). Scheduling keeps an already-running cadence, so re-calling begin(...) at launch does not reset the countdown. Calling begin(...) again replaces the previous subscription.
cancel()
fun cancel()
Cancels the periodic scrape and unsubscribes the callbacks. The client can be started again with begin(...).
close()
override fun close()
Releases the client: cancels the periodic scrape and unsubscribes the callbacks. From Closeable — call it when the client is no longer needed (for example in onDestroy()).
Provider Scope
Automated scrapes currently cover Gmail IMAP accounts with a non-empty username only. Other linked providers (Yahoo, AOL, Outlook) are skipped by the background scrape; the manual ImapClient.messages(...) and ImapClient.remoteMessages(...) paths are unaffected.
Requirements
- The scrape runs under a WorkManager periodic job with a
NetworkType.CONNECTEDconstraint and exponential backoff; WorkManager is initialized automatically and needs no manifest changes. - The schedule is tied to the linked accounts: it exists only while at least one eligible Gmail account is linked. It starts when such an account signs in (with the client started) and is cancelled when the last one signs out, so the job never keeps ticking for a signed-out user.
- Arm at process start: call
begin(...)fromApplication.onCreate(). Scheduled runs typically fire in the background with no activity alive — often a day after the app was last used — and a run that finds no armed client is skipped. Arming only in anActivitymeans background runs while the app is closed do not scrape. - Timing is best-effort: the interval is the earliest the job may run. Doze and App Standby buckets defer and batch background work on devices idle for a day or more, and some OEM battery managers restrict it further.
- Treat the callbacks as telemetry: each job's results are delivered server-side to the configured client endpoint, so a missed in-app callback never loses data. Persist what you need from the callback and rely on your backend as the source of truth.
Note: the client's opt-in state is not persisted by the SDK. The host owns the AutoScrapeClient — re-create it and call begin(...) at launch, before any scheduled run fires, and close() it when done.