FontsContract
  public
  
  
  
  class
  FontsContract
  
    extends Object
  
  
  
  
  
  
| java.lang.Object | |
| ↳ | android.provider.FontsContract | 
      This class was deprecated
      in API level 31.
    Use the Jetpack Core Library
      FontsContractCompat for consistent behavior across all
      devices.
  
Utility class to deal with Font ContentProviders.
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | FontsContract.Columns
      This class was deprecated
      in API level 31.
    Use the  | 
| 
        
        
        
        
        class | FontsContract.FontFamilyResult
      This class was deprecated
      in API level 31.
    Use the  | 
| 
        
        
        
        
        class | FontsContract.FontInfo
      This class was deprecated
      in API level 31.
    Use the  | 
| 
        
        
        
        
        class | FontsContract.FontRequestCallback
      This class was deprecated
      in API level 31.
    Use the  | 
| Public methods | |
|---|---|
| 
        
        
        static
        
        
        Typeface | 
      buildTypeface(Context context, CancellationSignal cancellationSignal, FontInfo[] fonts)
      Build a Typeface from an array of  | 
| 
        
        
        static
        
        
        FontsContract.FontFamilyResult | 
      fetchFonts(Context context, CancellationSignal cancellationSignal, FontRequest request)
      Fetch fonts given a font request. | 
| 
        
        
        static
        
        
        void | 
      requestFonts(Context context, FontRequest request, Handler handler, CancellationSignal cancellationSignal, FontsContract.FontRequestCallback callback)
      Create a typeface object given a font request. | 
| Inherited methods | |
|---|---|
Public methods
buildTypeface
public static Typeface buildTypeface (Context context, CancellationSignal cancellationSignal, FontInfo[] fonts)
Build a Typeface from an array of FontInfo
 Results that are marked as not ready will be skipped.
| Parameters | |
|---|---|
| context | Context: AContextthat will be used to fetch the font contents.
 This value cannot benull. | 
| cancellationSignal | CancellationSignal: A signal to cancel the operation in progress, or null if none. If
                           the operation is canceled, thenOperationCanceledExceptionwill be thrown. | 
| fonts | FontInfo: An array ofFontInfoto be used to create a Typeface.
 This value cannot benull. | 
| Returns | |
|---|---|
| Typeface | A Typeface object. Returns null if typeface creation fails. | 
fetchFonts
public static FontsContract.FontFamilyResult fetchFonts (Context context, CancellationSignal cancellationSignal, FontRequest request)
Fetch fonts given a font request.
| Parameters | |
|---|---|
| context | Context: AContextto be used for fetching fonts.
 This value cannot benull. | 
| cancellationSignal | CancellationSignal: A signal to cancel the operation in progress, or null if none. If
                           the operation is canceled, thenOperationCanceledExceptionwill be thrown when the
                           query is executed. | 
| request | FontRequest: AFontRequestobject that identifies the provider and query for the
                request.
 This value cannot benull. | 
| Returns | |
|---|---|
| FontsContract.FontFamilyResult | FontFamilyResultThis value cannot benull. | 
| Throws | |
|---|---|
| PackageManager.NameNotFoundException | If requested package or authority was not found in system. | 
requestFonts
public static void requestFonts (Context context, FontRequest request, Handler handler, CancellationSignal cancellationSignal, FontsContract.FontRequestCallback callback)
Create a typeface object given a font request. The font will be asynchronously fetched,
 therefore the result is delivered to the given callback. See FontRequest.
 Only one of the methods in callback will be invoked, depending on whether the request
 succeeds or fails. These calls will happen on the caller thread.
 Note that the result Typeface may be cached internally and the same instance will be returned
 the next time you call this method with the same request. If you want to bypass this cache,
 use fetchFonts(Context, CancellationSignal, FontRequest) and buildTypeface(Context, CancellationSignal, FontInfo) instead.
| Parameters | |
|---|---|
| context | Context: A context to be used for fetching from font provider.
 This value cannot benull. | 
| request | FontRequest: AFontRequestobject that identifies the provider and query for the
                request. May not be null. | 
| handler | Handler: A handler to be processed the font fetching.
 This value cannot benull. | 
| cancellationSignal | CancellationSignal: A signal to cancel the operation in progress, or null if none. If
                           the operation is canceled, thenOperationCanceledExceptionwill be thrown. | 
| callback | FontsContract.FontRequestCallback: A callback that will be triggered when results are obtained. May not 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 2025-02-10 UTC.
