ContentSafetyManager


public final class ContentSafetyManager
extends Object

java.lang.Object
   ↳ android.app.contentsafety.ContentSafetyManager


The ContentSafetyManager provides access to content safety features.

It allows granted apps to manage content safety service configured on the device. Typical calling pattern will be to ERROR(/#checkContentRequest) and ERROR(/#isFeatureEnabledRequest) checkFile against sensitive content warnings.

Summary

Constants

String ACTION_SHOW_RESTRICTED_CONTENT_DETAILS

Activity Action: Launch an activity showing information about restricted content.

String EXTRA_CONTENT_LOCUS_ID

Extra for ACTION_SHOW_RESTRICTED_CONTENT_DETAILS containing the locus ID of the restricted content.

Public methods

Intent createContentRestrictedIntent(LocusId locusId)

Creates an Intent that can be used with Context.startActivity(Intent) to display a dialog about the restricted content.

boolean isContentSafetyEnabled()

Returns whether content safety is currently enabled for the user.

void requestContentClassification(ClassifiableContent content, Executor executor, ContentClassificationCallback callback)

Requests classification of the specified content.

Inherited methods

Constants

ACTION_SHOW_RESTRICTED_CONTENT_DETAILS

Added in API level 10000
public static final String ACTION_SHOW_RESTRICTED_CONTENT_DETAILS

Activity Action: Launch an activity showing information about restricted content.

Apps holding the RoleManager.ROLE_CONTENT_SAFETY must declare an activity that handles this action to show specific content restriction details.

Constant Value: "android.app.contentsafety.action.SHOW_RESTRICTED_CONTENT_DETAILS"

EXTRA_CONTENT_LOCUS_ID

Added in API level 10000
public static final String EXTRA_CONTENT_LOCUS_ID

Extra for ACTION_SHOW_RESTRICTED_CONTENT_DETAILS containing the locus ID of the restricted content.

Constant Value: "android.app.contentsafety.extra.CONTENT_LOCUS_ID"

Public methods

createContentRestrictedIntent

Added in API level 10000
public Intent createContentRestrictedIntent (LocusId locusId)

Creates an Intent that can be used with Context.startActivity(Intent) to display a dialog about the restricted content.

Parameters
locusId LocusId: the LocusId of the content to be restricted.
This value cannot be null.

Returns
Intent the intent to display the restricted content dialog.
This value may be null.

isContentSafetyEnabled

Added in API level 10000
public boolean isContentSafetyEnabled ()

Returns whether content safety is currently enabled for the user.

Returns
boolean true if content safety is enabled for the user, false otherwise

requestContentClassification

Added in API level 10000
public void requestContentClassification (ClassifiableContent content, 
                Executor executor, 
                ContentClassificationCallback callback)

Requests classification of the specified content.

When content safety is enabled, this method determines if the specified content is appropriate based on the user's settings.

If the content is classified, the result provided to the callback will have a classification type of ContentClassificationResult.TYPE_ALLOWED, ContentClassificationResult.TYPE_WARNING, or ContentClassificationResult.TYPE_BLOCKED. If the content could not be classified or if content safety is disabled, the classification type will be ContentClassificationResult.TYPE_UNCLASSIFIED.

Parameters
content ClassifiableContent: the content to be classified.
This value cannot be null.

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 ContentClassificationCallback: the callback to receive the classification result.
This value cannot be null.