Class ContentResolverDataProvider
-
- All Implemented Interfaces:
-
android.os.Parcelable
,com.pspdfkit.document.providers.DataProvider
,com.pspdfkit.document.providers.UriDataProvider
,com.pspdfkit.document.providers.WritableDataProvider
public 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 thecontent://
orfile://
scheme.
-
-
Field Summary
Fields Modifier and Type Field Description public final static Parcelable.Creator<ContentResolverDataProvider>
CREATOR
public final Uri
uri
public String
title
-
Constructor Summary
Constructors Constructor Description ContentResolverDataProvider(Uri uri)
Creates the data provider for loading a document from the given content provider uri
.
-
Method Summary
Modifier and Type Method Description Uri
getUri()
Returns the Uri from which this provided was created. String
getTitle()
Displayable document title to be used if PDF document does not contain metadata. long
getSize()
Return the actual file size of the PDF document which is provided by this data provider. String
getUid()
Unique document identifier used in all caching processes in PSPDFKit. int
describeContents()
void
writeToParcel(@NonNull() Parcel dest, int flags)
boolean
canWrite()
Indicates whether this data provider is writable. boolean
startWrite(WritableDataProvider.WriteMode writeMode)
Called before writing to the file begins so the provider can prepare file output. boolean
write(Array<byte> data)
Called by PSPDFKit to write data to the document. boolean
finishWrite()
Called by PSPDFKit after all data has been written via write method. boolean
supportsAppending()
Reports whether this provider supports appending to output file as opposed to always rewriting it. -
-
Constructor Detail
-
ContentResolverDataProvider
ContentResolverDataProvider(Uri uri)
Creates the data provider for loading a document from the given content provideruri
.- Parameters:
uri
- A content provider URI with supported scheme (content://
orfile://
).
-
-
Method Detail
-
getUri
@NonNull() Uri getUri()
Returns the Uri from which this provided was created.
- Returns:
The Uri this data provider was created from.
-
getTitle
@Nullable() 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.
-
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
@NonNull() 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.
-
describeContents
int describeContents()
-
writeToParcel
void writeToParcel(@NonNull() Parcel dest, int flags)
-
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(Array<byte> 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 write method. This allows the data provider to close all opened input streams. In case of 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 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 APPEND_TO_FILE save mode.
-
-
-
-