OpenShot Audio Library | OpenShotAudio 0.4.0
|
#include <juce_AndroidDocument.h>
Static Public Member Functions | |
static AndroidDocument | fromFile (const File &filePath) |
static AndroidDocument | fromDocument (const URL &documentUrl) |
static AndroidDocument | fromTree (const URL &treeUrl) |
Provides access to a document on Android devices.
In this context, a 'document' may be a file or a directory.
The main purpose of this class is to provide access to files in shared storage on Android. On newer Android versions, such files cannot be accessed directly by a file path, and must instead be read and modified using a new URI-based DocumentsContract API.
Example use-cases:
Note that you probably do not need this class if your app only needs to access files in its own internal sandbox. juce::File instances should work as expected in that case.
AndroidDocument is a bit like the DocumentFile class from the androidx extension library, in that it represents a single document, and is implemented using DocumentsContract functions.
Definition at line 241 of file juce_AndroidDocument.h.
juce::AndroidDocument::AndroidDocument | ( | ) |
Create a null document.
Referenced by copyDocumentToParentDocument(), createChildDirectory(), createChildDocumentWithTypeAndName(), fromDocument(), fromFile(), fromTree(), getNativeInfo(), moveDocumentFromParentToParent(), operator!=(), and operator==().
AndroidDocument juce::AndroidDocument::copyDocumentToParentDocument | ( | const AndroidDocument & | target | ) | const |
Experimental: Attempts to copy this document to a new parent, and returns an AndroidDocument representing the copy.
On failure, the returned AndroidDocument may be invalid, and will return false from hasValue().
This function may fail if the document doesn't allow copying, and when using URI-based documents on devices with API level 23 or lower. On failure, the returned AndroidDocument will return false from hasValue(). In testing, copying was not supported on the Android emulator for API 24, 30, or 31, so there's a good chance this function won't work on real devices.
AndroidDocument juce::AndroidDocument::createChildDirectory | ( | const String & | name | ) | const |
Attempts to create a new nested directory with a particular name.
On failure, the returned AndroidDocument may be invalid, and will return false from hasValue().
Referenced by createChildDirectory().
AndroidDocument juce::AndroidDocument::createChildDocumentWithTypeAndName | ( | const String & | type, |
const String & | name ) const |
Attempts to create a new nested document with a particular type and name.
The type should be a standard MIME type string, e.g. "image/png", "text/plain".
The file name doesn't need to contain an extension, as this information is passed via the type argument. If this document is File-based rather than URL-based, then an appropriate file extension will be chosen based on the MIME type.
On failure, the returned AndroidDocument may be invalid, and will return false from hasValue().
Referenced by createChildDocumentWithTypeAndName().
std::unique_ptr< InputStream > juce::AndroidDocument::createInputStream | ( | ) | const |
Creates a stream for reading from this document.
std::unique_ptr< OutputStream > juce::AndroidDocument::createOutputStream | ( | ) | const |
Creates a stream for writing to this document.
bool juce::AndroidDocument::deleteDocument | ( | ) | const |
Attempts to delete this document, and returns true on success.
Referenced by deleteDocument().
|
static |
Create an AndroidDocument representing a single document.
The argument should be a URL representing a document. Such URLs are returned by the system file-picker when it is not in folder-selection mode. If you pass a tree URL, this function will fail.
This function may fail on Android devices with API level 18 or lower, and on non-Android platforms. If this function fails, hasValue() will return false on the returned document. If calling this function fails, you may want to retry creating an AndroidDocument with fromFile(), passing the result of URL::getLocalFile().
Referenced by juce::URL::createOutputStream().
|
static |
Create an AndroidDocument representing a file or directory at a particular path.
This is provided for use on older API versions (lower than 19), or on other platforms, so that the same AndroidDocument API can be used regardless of the runtime platform version.
If the runtime platform version is 19 or higher, and you wish to work with a URI obtained from a native file picker, use fromDocument() or fromTree() instead.
If this function fails, hasValue() will return false on the returned document.
|
static |
Create an AndroidDocument representing the root of a tree of files.
The argument should be a URL representing a tree. Such URLs are returned by the system file-picker when it is in folder-selection mode. If you pass a URL referring to a document inside a tree, this will return a document referring to the root of the tree. If you pass a URL referring to a single file, this will fail.
When targeting platform version 30 or later, access to the filesystem via file paths is heavily restricted, and access to shared storage must use a new URI-based system instead. At time of writing, apps uploaded to the Play Store must target API 30 or higher. If you want read/write access to a shared folder, you must:
This function may fail on Android devices with API level 20 or lower, and on non-Android platforms. If this function fails, hasValue() will return false on the returned document.
AndroidDocumentInfo juce::AndroidDocument::getInfo | ( | ) | const |
Fetches information about this document.
NativeInfo juce::AndroidDocument::getNativeInfo | ( | ) | const |
|
inline |
True if this object actually refers to a document.
If this function returns false, you must not call any function on this instance other than the special member functions to copy, move, and/or destruct the instance.
Definition at line 344 of file juce_AndroidDocument.h.
Referenced by hasValue(), and operator bool().
bool juce::AndroidDocument::moveDocumentFromParentToParent | ( | const AndroidDocument & | currentParent, |
const AndroidDocument & | newParent ) |
Experimental: Attempts to move this document from one parent to another, and returns true on success.
This may cause the document's URI and metadata to change, so ensure to invalidate any cached information about the document (URLs, AndroidDocumentInfo instances) after calling this function.
This function may fail if the document doesn't allow moving, and when using URI-based documents on devices with API level 23 or lower.
|
inlineexplicit |
Like hasValue(), but allows declaring AndroidDocument instances directly in 'if' statements.
Definition at line 347 of file juce_AndroidDocument.h.
bool juce::AndroidDocument::operator!= | ( | const AndroidDocument & | ) | const |
False if the URLs of the two documents match.
bool juce::AndroidDocument::operator== | ( | const AndroidDocument & | ) | const |
True if the URLs of the two documents match.
bool juce::AndroidDocument::renameTo | ( | const String & | newDisplayName | ) |
Renames the document, and returns true on success.
This may cause the document's URI and metadata to change, so ensure to invalidate any cached information about the document (URLs, AndroidDocumentInfo instances) after calling this function.
Referenced by renameTo().