Class ContentResolverDataProvider

  • All Implemented Interfaces:
    android.os.Parcelable , com.pspdfkit.document.providers.DataProvider , com.pspdfkit.document.providers.UriDataProvider , com.pspdfkit.document.providers.WritableDataProvider

    
    public final class ContentResolverDataProvider
    extends InputStreamDataProvider implements Parcelable, WritableDataProvider, UriDataProvider
                        

    Data provider for opening PDF documents directly from a ContentProvider using Android's content resolver framework. PSPDFKit internally uses this data provider when loading a document from an Uri that uses the content:// or file:// scheme.

    Creates the data provider for loading a document from the given content provider uri.

    • Constructor Detail

      • ContentResolverDataProvider

        ContentResolverDataProvider(Uri uri)
        Parameters:
        uri - A content provider URI with supported scheme (content:// or file://).
    • Method Detail

      • getSize

         Long getSize()

        Return the actual file size of the PDF document which is provided by this data provider. If the data provider can't determine the correct file size (e.g. in case of an error) this method has to return FILE_SIZE_UNKNOWN.

        Returns:

        Returns size of PDF document data in bytes, or FILE_SIZE_UNKNOWN in case of an error.

      • getUid

         String getUid()

        Unique document identifier used in all caching processes in PSPDFKit. Must be equal or shorter than 50 chars. This method must be implemented for caching to work properly.

        Returns:

        Unique identifier of the provided document. Implementations may not return null or an exception will be thrown.

      • getTitle

         String getTitle()

        Displayable document title to be used if PDF document does not contain metadata. For example, for file-based providers this should return the filename. `.pdf` extensions will be stripped automatically.

        Returns:

        Fallback document title if PDF document does not contain the required metadata. May be null.

      • canWrite

         Boolean canWrite()

        Indicates whether this data provider is writable.

        Returns:

        true if the data provider can be written to, false if not.

      • startWrite

         Boolean startWrite(WritableDataProvider.WriteMode writeMode)

        Called before writing to the file begins so the provider can prepare file output.

        Parameters:
        writeMode - Determines how file data should be written to the output.
        Returns:

        true if operation succeeded, false if writing should be aborted.

      • write

         Boolean write(ByteArray data)

        Called by PSPDFKit to write data to the document. This callback will be called multiple times in a writing operation.

        Parameters:
        data - Data to be written to the file.
        Returns:

        true if writing succeeded, false if the write operation should be aborted.

      • finishWrite

         Boolean finishWrite()

        Called by PSPDFKit after all data has been written via method. This allows the data provider to close all opened input streams. In case of WriteMode.REWRITE_FILE access, the data provider should here replace the original file with the written temporary file.

        Returns:

        true if operation succeeded, false if it failed.

      • supportsAppending

         Boolean supportsAppending()

        Reports whether this provider supports appending to output file as opposed to always rewriting it. If this returns false, only WriteMode.REWRITE_FILE will be used and the PDF file will always be fully rewritten on save.

        Note that if true is returned here, both WriteMode options must be supported by this DataProvider since some documents cannot be saved incrementally.

        Returns:

        true if this provider supports WriteMode.APPEND_TO_FILE save mode.

      • getUri

         Uri getUri()

        Returns the Uri from which this provided was created.

        Returns:

        The Uri this data provider was created from.