-
public final class VoiceContextRegistryRegistry for contextual information that the voice assistant uses to enrich its system prompt.
External applications use this class to register VoiceContextInfo entries — descriptive metadata such as the active unit system, the purpose of the host application, or the current work context. These entries are not callable tools; they provide background knowledge that helps the LLM generate more relevant responses.
The host app registers one or more VoiceContextInfo entries via registerContext or registerAllContext.
The registry stores them keyed by VoiceContextInfo.key for deduplication.
A VoiceToolContract.ACTION_CONTEXT_CHANGED broadcast is sent so the voice assistant app re-queries the VoiceContextProvider ContentProvider and refreshes the system prompt.
Inject the registry and register context entries at app startup:
@Singleton class MyAppInitializer @Inject constructor( private val contextRegistry: VoiceContextRegistry ) { fun initialize() { contextRegistry.registerContext( VoiceContextInfo( key = "unit_system", description = "The operator uses metric units." ) ) contextRegistry.registerContext( VoiceContextInfo( key = "app_purpose", description = "This application manages on-board weighing for loading operations." ) ) } }The VoiceContextProvider ContentProvider must be declared in your app's
AndroidManifest.xml. If you include theVoiceAssistCapabilitieslibrary as a dependency, this is handled automatically via manifest merging.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classVoiceContextRegistry.Companion
-
Constructor Summary
Constructors Constructor Description VoiceContextRegistry(Context context)
-
Method Summary
Modifier and Type Method Description final UnitregisterContext(VoiceContextInfo info, Boolean broadcastIntent)Register a single context entry. final UnitregisterAllContext(Set<VoiceContextInfo> entries, Boolean broadcastIntent)Replace all registered context entries with the given set. final BooleanunregisterContext(String key, Boolean broadcastIntent)Remove a previously registered context entry by its key. final UnitunregisterAllContext()Remove all registered context entries and broadcast the change. final List<VoiceContextInfo>getRegisteredContext()Returns all currently registered context entries. final VoiceContextInfogetContext(String key)Returns a specific context entry by key, or nullif not found.-
-
Constructor Detail
-
VoiceContextRegistry
VoiceContextRegistry(Context context)
-
-
Method Detail
-
registerContext
final Unit registerContext(VoiceContextInfo info, Boolean broadcastIntent)
Register a single context entry. If an entry with the same VoiceContextInfo.key already exists, it is replaced.
- Parameters:
info- The context entry to register.broadcastIntent- Whether to send an VoiceToolContract.
-
registerAllContext
final Unit registerAllContext(Set<VoiceContextInfo> entries, Boolean broadcastIntent)
Replace all registered context entries with the given set.
- Parameters:
entries- The full set of context entries to register.broadcastIntent- Whether to broadcast the change.
-
unregisterContext
final Boolean unregisterContext(String key, Boolean broadcastIntent)
Remove a previously registered context entry by its key.
- Parameters:
key- The key of the context entry to remove.broadcastIntent- Whether to broadcast the change.
-
unregisterAllContext
final Unit unregisterAllContext()
Remove all registered context entries and broadcast the change.
-
getRegisteredContext
final List<VoiceContextInfo> getRegisteredContext()
Returns all currently registered context entries.
-
getContext
final VoiceContextInfo getContext(String key)
Returns a specific context entry by key, or
nullif not found.
-
-
-
-