Added in API level 33

DevicePolicyResourcesManager


public class DevicePolicyResourcesManager
extends Object

java.lang.Object
   ↳ android.app.admin.DevicePolicyResourcesManager


Class containing required APIs to set, reset, and get device policy related resources.

Summary

Public methods

Drawable getDrawable(String drawableId, String drawableStyle, Supplier<Drawable> defaultDrawableLoader)

Returns the appropriate updated drawable for the drawableId with style drawableStyle if one was set using setDrawables, otherwise returns the drawable from defaultDrawableLoader.

Drawable getDrawable(String drawableId, String drawableStyle, String drawableSource, Supplier<Drawable> defaultDrawableLoader)

Similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier), but also accepts a drawableSource which could result in returning a different drawable than getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier) if an override was set for that specific source.

Icon getDrawableAsIcon(String drawableId, String drawableStyle, String drawableSource, Icon defaultIcon)

Similar to getDrawable(java.lang.String, java.lang.String, java.lang.String, java.util.function.Supplier) but returns an Icon instead of a Drawable.

Icon getDrawableAsIcon(String drawableId, String drawableStyle, Icon defaultIcon)

Similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier) but returns an Icon instead of a Drawable.

Drawable getDrawableForDensity(String drawableId, String drawableStyle, int density, Supplier<Drawable> defaultDrawableLoader)

Similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier), but also accepts density.

Drawable getDrawableForDensity(String drawableId, String drawableStyle, String drawableSource, int density, Supplier<Drawable> defaultDrawableLoader)

Similar to getDrawable(java.lang.String, java.lang.String, java.lang.String, java.util.function.Supplier), but also accepts density.

String getString(String stringId, Supplier<String> defaultStringLoader, Object... formatArgs)

Similar to getString(java.lang.String, java.util.function.Supplier) but accepts formatArgs and returns a localized formatted string, substituting the format arguments as defined in Formatter and String.format(String, Object), (see Resources#getString(int, Object...)).

String getString(String stringId, Supplier<String> defaultStringLoader)

Returns the appropriate updated string for the stringId (see DevicePolicyResources.Strings) if one was set using setStrings, otherwise returns the string from defaultStringLoader.

Inherited methods

Public methods

getDrawable

Added in API level 33
public Drawable getDrawable (String drawableId, 
                String drawableStyle, 
                Supplier<Drawable> defaultDrawableLoader)

Returns the appropriate updated drawable for the drawableId with style drawableStyle if one was set using setDrawables, otherwise returns the drawable from defaultDrawableLoader.

Also returns the drawable from defaultDrawableLoader if drawableId is DevicePolicyResources#UNDEFINED.

Calls to this API will not return null unless no updated drawable was found and the call to defaultDrawableLoader returned null.

This API uses the screen density returned from Resources#getConfiguration(), to set a different value use getDrawableForDensity(java.lang.String, java.lang.String, int, java.util.function.Supplier).

Callers should register for DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED to get notified when a resource has been updated.

Note that each call to this API loads the resource from the package that called setDrawables to set the updated resource.

Parameters
drawableId String: The drawable ID to get the updated resource for. This value cannot be null.

drawableStyle String: The drawable style to use. This value cannot be null.

defaultDrawableLoader Supplier: To get the default drawable if no updated drawable was set for the provided params. This value cannot be null.

Returns
Drawable

getDrawable

Added in API level 33
public Drawable getDrawable (String drawableId, 
                String drawableStyle, 
                String drawableSource, 
                Supplier<Drawable> defaultDrawableLoader)

Similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier), but also accepts a drawableSource which could result in returning a different drawable than getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier) if an override was set for that specific source.

If drawableSource is DevicePolicyResources#UNDEFINED, it returns the appropriate string for drawableId and drawableStyle similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier).

Calls to this API will not return null unless no updated drawable was found and the call to defaultDrawableLoader returned null.

Callers should register for DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED to get notified when a resource has been updated.

Parameters
drawableId String: The drawable ID to get the updated resource for. This value cannot be null.

drawableStyle String: The drawable style to use. This value cannot be null.

drawableSource String: The source for the caller. This value cannot be null.

defaultDrawableLoader Supplier: To get the default drawable if no updated drawable was set for the provided params. This value cannot be null.

Returns
Drawable

getDrawableAsIcon

Added in API level 33
public Icon getDrawableAsIcon (String drawableId, 
                String drawableStyle, 
                String drawableSource, 
                Icon defaultIcon)

Similar to getDrawable(java.lang.String, java.lang.String, java.lang.String, java.util.function.Supplier) but returns an Icon instead of a Drawable.

Parameters
drawableId String: The drawable ID to get the updated resource for. This value cannot be null.

drawableStyle String: The drawable style to use. This value cannot be null.

drawableSource String: The source for the caller. This value cannot be null.

defaultIcon Icon: Returned if no updated drawable was set for the provided params. This value may be null.

Returns
Icon This value may be null.

getDrawableAsIcon

Added in API level 33
public Icon getDrawableAsIcon (String drawableId, 
                String drawableStyle, 
                Icon defaultIcon)

Similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier) but returns an Icon instead of a Drawable.

Parameters
drawableId String: The drawable ID to get the updated resource for. This value cannot be null.

drawableStyle String: The drawable style to use. This value cannot be null.

defaultIcon Icon: Returned if no updated drawable was set for the provided params. This value may be null.

Returns
Icon This value may be null.

getDrawableForDensity

Added in API level 33
public Drawable getDrawableForDensity (String drawableId, 
                String drawableStyle, 
                int density, 
                Supplier<Drawable> defaultDrawableLoader)

Similar to getDrawable(java.lang.String, java.lang.String, java.util.function.Supplier), but also accepts density. See Resources#getDrawableForDensity(int, int, Resources.Theme).

Calls to this API will not return null unless no updated drawable was found and the call to defaultDrawableLoader returned null.

Callers should register for DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED to get notified when a resource has been updated.

Parameters
drawableId String: The drawable ID to get the updated resource for. This value cannot be null.

drawableStyle String: The drawable style to use. This value cannot be null.

density int: The desired screen density indicated by the resource as found in DisplayMetrics. A value of 0 means to use the density returned from Resources#getConfiguration().

defaultDrawableLoader Supplier: To get the default drawable if no updated drawable was set for the provided params. This value cannot be null.

Returns
Drawable

getDrawableForDensity

Added in API level 33
public Drawable getDrawableForDensity (String drawableId, 
                String drawableStyle, 
                String drawableSource, 
                int density, 
                Supplier<Drawable> defaultDrawableLoader)

Similar to getDrawable(java.lang.String, java.lang.String, java.lang.String, java.util.function.Supplier), but also accepts density. See Resources#getDrawableForDensity(int, int, Resources.Theme).

Calls to this API will not return null unless no updated drawable was found and the call to defaultDrawableLoader returned null.

Callers should register for DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED to get notified when a resource has been updated.

Parameters
drawableId String: The drawable ID to get the updated resource for. This value cannot be null.

drawableStyle String: The drawable style to use. This value cannot be null.

drawableSource String: The source for the caller. This value cannot be null.

density int: The desired screen density indicated by the resource as found in DisplayMetrics. A value of 0 means to use the density returned from Resources#getConfiguration().

defaultDrawableLoader Supplier: To get the default drawable if no updated drawable was set for the provided params. This value cannot be null.

Returns
Drawable

getString

Added in API level 33
public String getString (String stringId, 
                Supplier<String> defaultStringLoader, 
                Object... formatArgs)

Similar to getString(java.lang.String, java.util.function.Supplier) but accepts formatArgs and returns a localized formatted string, substituting the format arguments as defined in Formatter and String.format(String, Object), (see Resources#getString(int, Object...)).

Calls to this API will not return null unless no updated drawable was found and the call to defaultStringLoader returned null.

Parameters
stringId String: The IDs to get the updated resource for. This value cannot be null.

defaultStringLoader Supplier: To get the default string if no updated string was set for stringId. This value cannot be null.

formatArgs Object: The format arguments that will be used for substitution. This value cannot be null.

Returns
String

getString

Added in API level 33
public String getString (String stringId, 
                Supplier<String> defaultStringLoader)

Returns the appropriate updated string for the stringId (see DevicePolicyResources.Strings) if one was set using setStrings, otherwise returns the string from defaultStringLoader.

Also returns the string from defaultStringLoader if stringId is DevicePolicyResources#UNDEFINED.

Calls to this API will not return null unless no updated drawable was found and the call to defaultStringLoader returned null.

Callers should register for DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED to get notified when a resource has been updated.

Note that each call to this API loads the resource from the package that called setStrings to set the updated resource.

Parameters
stringId String: The IDs to get the updated resource for. This value cannot be null.

defaultStringLoader Supplier: To get the default string if no updated string was set for stringId. This value cannot be null.

Returns
String