AppDataFileSource
class AppDataFileSource : OperationSource
| kotlin.Any | ||
| ↳ | android.os.storage.operations.sources.OperationSource | |
| ↳ | android.os.storage.operations.sources.AppDataFileSource | |
A source representing a file within the calling application's private app data directory.
This source is restricted to files located inside the application's internal data directory (as returned by android.content.Context#getDataDir()).
Operation Rejection
To ensure system security and integrity, operations using an AppDataFileSource will be rejected with android.os.storage.operations.FileOperationResult#ERROR_UNSUPPORTED_SOURCE or android.os.storage.operations.FileOperationResult#ERROR_INVALID_REQUEST if:
- The provided path is not absolute.
- The path contains path traversal elements (e.g., "..") or redundant segments.
- The path contains unsafe control characters (e.g., null, newline).
- The file is outside the application's internal data directory (CE or DE storage). Locations such as external storage or system directories are strictly prohibited.
Example Usage:
<code>// Obtain the application's data directory using Context Context context = getApplicationContext(); File myDataFile = new File(context.getDataDir(), "subfolder/my_data.txt"); // Construct the AppDataFileSource with the File object AppDataFileSource source = new AppDataFileSource(myDataFile); // The source can now be used in storage operations </code>
Summary
| Public constructors | |
|---|---|
AppDataFileSource(file: File)Creates a new source for the specified file. |
|
| Public methods | |
|---|---|
| File |
getFile()Returns the file associated with this source. |
| String |
toString()Returns a string representation of this source for debugging. |
Public constructors
AppDataFileSource
AppDataFileSource(file: File)
Creates a new source for the specified file.
| Parameters | |
|---|---|
file |
File: The file to be used as a source. Must be within the application's data directory. This value cannot be null. |
Public methods
getFile
fun getFile(): File
Returns the file associated with this source.
| Return | |
|---|---|
File |
This value cannot be null. |
toString
fun toString(): String
Returns a string representation of this source for debugging.
| Return | |
|---|---|
String |
A string containing the source type and path. This value cannot be null. |