PersonalContextManager
public
final
class
PersonalContextManager
extends Object
| java.lang.Object | |
| ↳ | android.app.personalcontext.PersonalContextManager |
Client facing access to the PersonalContext service.
The PersonalContext service is a framework for securely gathering device context (such as screen context and device state changes) and delivering it to a set of system configured components to combine and infer personalized information and actions. The personalized contextual information used by the PersonalContext service is implementation specific to the participating component. The resulting output is shown in contextually relevant environment, such as notification replies or auto-fill suggestions.
The service accepts a flow of contextual details from activity on the device, such as
notifications and screen content. This data is used by a set of components to determine relevant
information and suggestions for the user. The incoming data takes the form of various ContextHint subclasses, each tailored to a particular captured data type. Entities both inside
and outside the PersonalContext service through ERROR(publishTriggeringHint(List,List)/#publishTriggeringHint(java.util.List,java.util.List) publishTriggeringHint(List,List)) and
its variants.
Often times, the publisher might know that the results should be delivered to a particular
surface to render. For example, NotificationHint can
lead to actions or suggestions within the notification shade. In these cases, the surface can be
targeted by the publisher to receiving the results by specifying the ERROR(RenderToken/android.app.personalcontext.RenderToken RenderToken)
associated with the surface's renderer.
Core PersonalContext entities and roles:
ContextHintimplementations are the input into the PersonalContext service. Each subclass captures domain specific information about a particular device activity, such asCallHint.- @link
ContextInsightrepresents information and actions derived fromContextHints. This information is domain agnostic, allowing for display in different environments. ERROR(/android.app.personalcontext.refiner.HintRefinerService)receiveContextHints and have the opportunity to generateContextHints based on the input data.ERROR(/android.app.personalcontext.understander.ContextUnderstanderService)is downstream fromERROR(/android.app.personalcontext.refiner.HintRefinerService)s receiving all generatedContextHints based on its specifiedHintFilter. An understander service is not required to produceContextInsights from the inboundContextHints and may produceContextInsights by callingERROR(publishInsight(List)/#publishInsight(java.util.List) publishInsight(List))at any time.ERROR(/android.app.personalcontext.renderer.InsightRendererService)handle showing resultingContextInsights. Renderers integrate with their given surfaces, such as notifications and auto-fill suggestions.ERROR(RenderToken/android.app.personalcontext.RenderToken RenderToken)allow forContextHintpublishers to specify theERROR(/android.app.personalcontext.renderer.InsightRendererService)that should anyContextInsightgenerated from the hint.
Summary
Nested classes | |
|---|---|
interface |
PersonalContextManager.OnPersonalContextModeChangedListener
Callback interface to receive updates when personal context mode for an application changes. |
Constants | |
|---|---|
String |
ACTION_LAUNCH_PERSONAL_CONTEXT_UNDERSTANDER_CONSENT_INTRO
Activity Action: Start an activity that prompts the user with understander-specific consent information. |
String |
ACTION_PERSONAL_CONTEXT_ENABLED_CHANGED
Intent that is broadcast when the state of |
int |
DESTINATION_AUGMENTED_AUTOFILL
Destination for augmented autofill responses that show inline in the IME's suggestion bar. |
int |
DESTINATION_EMBEDDED
Destination for an embedded visualization. |
int |
DESTINATION_NOTIFICATION
Destination for suggestion chips in notifications. |
int |
DESTINATION_REMOTE_AUTOFILL
Destination for screen whispers in the status bar that fill in text in an app's text input on activation. |
int |
DESTINATION_SCREEN_WHISPER
Destination for screen whispers in the status bar. |
int |
DESTINATION_UNIVERSAL
Destination for a general-purpose surface for displaying insights that is provided by the device manufacturer. |
int |
DESTINATION_UNKNOWN
Unknown destination type. |
String |
EXTRA_FEEDBACK_REQUEST
Intent Extra: The name of the extra storing the |
String |
EXTRA_PROMPT_REQUEST
Intent Extra: The |
String |
PERSONAL_CONTEXT_SERVICE
The name of the Personal Context service. |
int |
UNDERSTANDER_TYPE_AGENT
Understander type for a personal context understander that is provided by the user-selected
digital assistant on the device, implementing |
int |
UNDERSTANDER_TYPE_OEM
Understander type for a personal context understander that is provided by the device
manufacturer, implementing |
int |
UNDERSTANDER_TYPE_UNKNOWN
Unknown understander type. |
Public methods | |
|---|---|
List<ComponentName>
|
getEnabledUnderstanders()
Returns the list of enabled personal context understanders. |
boolean
|
isEnabled()
Returns whether the Personal Context service is enabled system-wide. |
boolean
|
isPersonalContextModeEnabled(String packageName)
Returns |
boolean
|
isPersonalContextModeEnabled()
Returns |
void
|
registerOnPersonalContextEnabledChangedListener(Executor executor, Runnable listener)
Registers a listener to be notified when the overall personal context service enabled state changes. |
void
|
registerOnPersonalContextModeChangedListener(String packageName, Executor executor, PersonalContextManager.OnPersonalContextModeChangedListener listener)
Registers a listener to be notified when the personal context mode setting for a specific package changes. |
void
|
registerOnPersonalContextModeChangedListener(Executor executor, PersonalContextManager.OnPersonalContextModeChangedListener listener)
Registers a listener to be notified when the personal context mode setting for the calling application changes. |
void
|
registerUnderstanderCallback(Executor executor, Runnable callback)
Registers a callback to be notified when the list of enabled personal context understanders changes. |
void
|
respondToPrompt(PromptResponse promptResponse)
Responds to a prompt with the chosen insight. |
void
|
respondToUnderstanderRegistrationRequest(RegistrationResponse response)
Responds to an understander registration request. |
void
|
unregisterOnPersonalContextEnabledChangedListener(Runnable listener)
Unregisters a listener previously registered with |
void
|
unregisterOnPersonalContextModeChangedListener(PersonalContextManager.OnPersonalContextModeChangedListener listener)
Unregisters a listener previously registered with |
void
|
unregisterUnderstanderCallback(Runnable callback)
Unregisters a previously registered callback. |
Inherited methods | |
|---|---|
Constants
ACTION_LAUNCH_PERSONAL_CONTEXT_UNDERSTANDER_CONSENT_INTRO
public static final String ACTION_LAUNCH_PERSONAL_CONTEXT_UNDERSTANDER_CONSENT_INTRO
Activity Action: Start an activity that prompts the user with understander-specific consent information.
This action is handled by an activity in the package of the understander component. If no activity is specified, this consent introduction is skipped and the user is directly prompted with system consent dialog for the understander.
The result of this activity should be passed back through the ResultReceiver stored in ERROR(/#EXTRA_PERSONAL_CONTEXT_UNDERSTANDER_CONSENT_INTRO_RESULT_RECEIVER) extra.
Constant Value: "android.app.personalcontext.action.LAUNCH_PERSONAL_CONTEXT_UNDERSTANDER_CONSENT_INTRO"
ACTION_PERSONAL_CONTEXT_ENABLED_CHANGED
public static final String ACTION_PERSONAL_CONTEXT_ENABLED_CHANGED
Intent that is broadcast when the state of isEnabled() changes. This broadcast is
only sent to registered receivers.
Constant Value: "android.app.personalcontext.action.PERSONAL_CONTEXT_ENABLED_CHANGED"
DESTINATION_AUGMENTED_AUTOFILL
public static final int DESTINATION_AUGMENTED_AUTOFILL
Destination for augmented autofill responses that show inline in the IME's suggestion bar.
This destination only accepts a AugmentedAutofillInsight.
Constant Value: 16 (0x00000010)
DESTINATION_EMBEDDED
public static final int DESTINATION_EMBEDDED
Destination for an embedded visualization.
The presence of this destination indicates that the hint was sent in by a client app
requesting a visualization. The understander should set an InsightVisualizerSession
via UnderstandResult.Builder.setVisualizerSession(InsightVisualizerSession)
to indicate that it wants to generate a visualization for the client. The initial hint, and
all additional hints from the client for this session, will be provided directly to InsightVisualizerSession.createRemoteViewsForHints. If an InsightVisualizerSession
is not provided for this destination, the visualization session will be closed.
No insight should be provided for this destination, it will be ignored.
This destination will only be provided to agent understanders registered with ERROR(UnderstanderType.UNDERSTANDER_TYPE_AGENT/android.app.personalcontext.PersonalContextManager.UnderstanderType#UNDERSTANDER_TYPE_AGENT UnderstanderType.UNDERSTANDER_TYPE_AGENT).
Constant Value: 32 (0x00000020)
DESTINATION_NOTIFICATION
public static final int DESTINATION_NOTIFICATION
Destination for suggestion chips in notifications. This destination only accepts a NotificationInsight.
Constant Value: 2 (0x00000002)
DESTINATION_REMOTE_AUTOFILL
public static final int DESTINATION_REMOTE_AUTOFILL
Destination for screen whispers in the status bar that fill in text in an app's text input on
activation. This destination only accepts a ScreenWhisperAutofillInsight.
Constant Value: 8 (0x00000008)
DESTINATION_SCREEN_WHISPER
public static final int DESTINATION_SCREEN_WHISPER
Destination for screen whispers in the status bar. This destination only accepts a ScreenWhisperInsight.
Constant Value: 4 (0x00000004)
DESTINATION_UNIVERSAL
public static final int DESTINATION_UNIVERSAL
Destination for a general-purpose surface for displaying insights that is provided by the device manufacturer.
This destination will only be provided to OEM understanders registered with ERROR(UnderstanderType.UNDERSTANDER_TYPE_OEM/android.app.personalcontext.PersonalContextManager.UnderstanderType#UNDERSTANDER_TYPE_OEM UnderstanderType.UNDERSTANDER_TYPE_OEM).
Constant Value: 1 (0x00000001)
DESTINATION_UNKNOWN
public static final int DESTINATION_UNKNOWN
Unknown destination type. The framework will never deliberately send this type. No response is expected, and any response will be ignored.
Constant Value: 0 (0x00000000)
EXTRA_FEEDBACK_REQUEST
public static final String EXTRA_FEEDBACK_REQUEST
Intent Extra: The name of the extra storing the FeedbackRequest in the bundle that
the understander's feedback activity is started with.
Constant Value: "android.app.personalcontext.extra.FEEDBACK_REQUEST"
EXTRA_PROMPT_REQUEST
public static final String EXTRA_PROMPT_REQUEST
Intent Extra: The PromptRequest associated with a prompt.
This is a PromptRequest extra.
Constant Value: "android.app.personalcontext.extra.PROMPT_REQUEST"
PERSONAL_CONTEXT_SERVICE
public static final String PERSONAL_CONTEXT_SERVICE
The name of the Personal Context service.
Constant Value: "personal_context"
UNDERSTANDER_TYPE_AGENT
public static final int UNDERSTANDER_TYPE_AGENT
Understander type for a personal context understander that is provided by the user-selected
digital assistant on the device, implementing ERROR(/android.app.personalcontext.understander.ContextUnderstanderService).
The user must consent before the understander can participate in the personal context flow.
Constant Value: 1 (0x00000001)
UNDERSTANDER_TYPE_OEM
public static final int UNDERSTANDER_TYPE_OEM
Understander type for a personal context understander that is provided by the device
manufacturer, implementing ERROR(/android.app.personalcontext.understander.ContextUnderstanderService).
Like UNDERSTANDER_TYPE_AGENT, the user must consent before the understander can
participate in the personal context flow.
Data egress will be more limited for an OEM understander. For instance,
UnderstandRequest.getSessionId() will
return null.
Constant Value: 2 (0x00000002)
UNDERSTANDER_TYPE_UNKNOWN
public static final int UNDERSTANDER_TYPE_UNKNOWN
Unknown understander type.
Constant Value: 0 (0x00000000)
Public methods
getEnabledUnderstanders
public List<ComponentName> getEnabledUnderstanders ()
Returns the list of enabled personal context understanders.
| Returns | |
|---|---|
List<ComponentName> |
The list of currently enabled understanders.
This value cannot be null. |
isEnabled
public boolean isEnabled ()
Returns whether the Personal Context service is enabled system-wide.
| Returns | |
|---|---|
boolean |
|
isPersonalContextModeEnabled
public boolean isPersonalContextModeEnabled (String packageName)
Returns true if personal context data collection is enabled for the given package.
When disabled, this setting stops all data collection sources of personal context for a particular application, such as from the Content Capture API and notifications content. As a result, contextual information from this application will not participate in the data capture and processing within the PersonalContext service, excluding this information from being seen by participating components and thus restricting any PersonalContext experience from including this application.
Querying information about a package other than the caller's package requires Manifest.permission.QUERY_ALL_PACKAGES.
| Parameters | |
|---|---|
packageName |
String: package name of the application to read the setting for.
This value cannot be null. |
| Returns | |
|---|---|
boolean |
|
isPersonalContextModeEnabled
public boolean isPersonalContextModeEnabled ()
Returns true if personal context data collection is enabled for the calling package.
When disabled, this setting stops all data collection sources of personal context for a particular application, such as from the Content Capture API and notifications content. As a result, contextual information from this application will not participate in the data capture and processing within the PersonalContext service, excluding this information from being seen by participating components and thus restricting any PersonalContext experience from including this application.
| Returns | |
|---|---|
boolean |
|
registerOnPersonalContextEnabledChangedListener
public void registerOnPersonalContextEnabledChangedListener (Executor executor, Runnable listener)
Registers a listener to be notified when the overall personal context service enabled state changes.
| Parameters | |
|---|---|
executor |
Executor: the executor on which the listener will be called.
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor().
Otherwise, provide an Executor that dispatches to an appropriate thread. |
listener |
Runnable: the listener to register.
This value cannot be null. |
registerOnPersonalContextModeChangedListener
public void registerOnPersonalContextModeChangedListener (String packageName, Executor executor, PersonalContextManager.OnPersonalContextModeChangedListener listener)
Registers a listener to be notified when the personal context mode setting for a specific package changes.
Querying information about a package other than the caller's package requires package
visibility (e.g. via QUERY_ALL_PACKAGES or <queries> in the manifest).
| Parameters | |
|---|---|
packageName |
String: package name of the application to listen for setting changes.
This value cannot be null. |
executor |
Executor: the executor on which the listener will be called.
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor().
Otherwise, provide an Executor that dispatches to an appropriate thread. |
listener |
PersonalContextManager.OnPersonalContextModeChangedListener: the listener to register.
This value cannot be null. |
| Throws | |
|---|---|
SecurityException |
if the caller cannot query the personal context mode for the specified package |
registerOnPersonalContextModeChangedListener
public void registerOnPersonalContextModeChangedListener (Executor executor, PersonalContextManager.OnPersonalContextModeChangedListener listener)
Registers a listener to be notified when the personal context mode setting for the calling application changes.
| Parameters | |
|---|---|
executor |
Executor: the executor on which the listener will be called.
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor().
Otherwise, provide an Executor that dispatches to an appropriate thread. |
listener |
PersonalContextManager.OnPersonalContextModeChangedListener: the listener to register.
This value cannot be null. |
registerUnderstanderCallback
public void registerUnderstanderCallback (Executor executor, Runnable callback)
Registers a callback to be notified when the list of enabled personal context understanders changes.
This callback registration does not require any permissions. When notified of a change,
clients can poll the relevant settings (e.g. calling getEnabledUnderstanders())
to obtain updated state.
| Parameters | |
|---|---|
executor |
Executor: The executor on which to run the callback.
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor().
Otherwise, provide an Executor that dispatches to an appropriate thread. |
callback |
Runnable: The callback to register.
This value cannot be null. |
respondToPrompt
public void respondToPrompt (PromptResponse promptResponse)
Responds to a prompt with the chosen insight.
| Parameters | |
|---|---|
promptResponse |
PromptResponse: the response containing the chosen insight.
This value cannot be null. |
respondToUnderstanderRegistrationRequest
public void respondToUnderstanderRegistrationRequest (RegistrationResponse response)
Responds to an understander registration request.
| Parameters | |
|---|---|
response |
RegistrationResponse: The response to return.
This value cannot be null. |
unregisterOnPersonalContextEnabledChangedListener
public void unregisterOnPersonalContextEnabledChangedListener (Runnable listener)
Unregisters a listener previously registered with registerOnPersonalContextEnabledChangedListener(Executor, Runnable).
| Parameters | |
|---|---|
listener |
Runnable: the listener to unregister.
This value cannot be null. |
unregisterOnPersonalContextModeChangedListener
public void unregisterOnPersonalContextModeChangedListener (PersonalContextManager.OnPersonalContextModeChangedListener listener)
Unregisters a listener previously registered with registerOnPersonalContextModeChangedListener(String, Executor, OnPersonalContextModeChangedListener).
| Parameters | |
|---|---|
listener |
PersonalContextManager.OnPersonalContextModeChangedListener: the listener to unregister.
This value cannot be null. |
unregisterUnderstanderCallback
public void unregisterUnderstanderCallback (Runnable callback)
Unregisters a previously registered callback.
| Parameters | |
|---|---|
callback |
Runnable: The callback to unregister.
This value cannot be null. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-08-28 UTC.