AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.File Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.File:
com.google.appinventor.components.runtime.AndroidNonvisibleComponent com.google.appinventor.components.runtime.Component com.google.appinventor.components.runtime.Component

Public Member Functions

 File (ComponentContainer container)
 
void SaveFile (String text, String fileName)
 
void AppendToFile (String text, String fileName)
 
void ReadFrom (final String fileName)
 
void Delete (final String fileName)
 
void GotText (String text)
 
void AfterFileSaved (String fileName)
 
- Public Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
HandlesEventDispatching getDispatchDelegate ()
 

Additional Inherited Members

- Static Public Attributes inherited from com.google.appinventor.components.runtime.Component
static final String ASSET_DIRECTORY = "component"
 
static final int ALIGNMENT_NORMAL = 0
 
static final int ALIGNMENT_CENTER = 1
 
static final int ALIGNMENT_OPPOSITE = 2
 
static final int ACCELEROMETER_SENSITIVITY_WEAK = 1
 
static final int ACCELEROMETER_SENSITIVITY_MODERATE = 2
 
static final int ACCELEROMETER_SENSITIVITY_STRONG = 3
 
static final int BUTTON_SHAPE_DEFAULT = 0
 
static final int BUTTON_SHAPE_ROUNDED = 1
 
static final int BUTTON_SHAPE_RECT = 2
 
static final int BUTTON_SHAPE_OVAL = 3
 
static final int COLOR_NONE = 0x00FFFFFF
 
static final int COLOR_BLACK = 0xFF000000
 
static final int COLOR_BLUE = 0xFF0000FF
 
static final int COLOR_CYAN = 0xFF00FFFF
 
static final int COLOR_DKGRAY = 0xFF444444
 
static final int COLOR_GRAY = 0xFF888888
 
static final int COLOR_GREEN = 0xFF00FF00
 
static final int COLOR_LTGRAY = 0xFFCCCCCC
 
static final int COLOR_MAGENTA = 0xFFFF00FF
 
static final int COLOR_ORANGE = 0xFFFFC800
 
static final int COLOR_PINK = 0xFFFFAFAF
 
static final int COLOR_RED = 0xFFFF0000
 
static final int COLOR_WHITE = 0xFFFFFFFF
 
static final int COLOR_YELLOW = 0xFFFFFF00
 
static final int COLOR_DEFAULT = 0x00000000
 
static final String DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF"
 
static final String DEFAULT_VALUE_COLOR_BLACK = "&HFF000000"
 
static final String DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF"
 
static final String DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF"
 
static final String DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444"
 
static final String DEFAULT_VALUE_COLOR_GRAY = "&HFF888888"
 
static final String DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00"
 
static final String DEFAULT_VALUE_COLOR_LTGRAY = "&HFFCCCCCC"
 
static final String DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF"
 
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
 
static final String DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF"
 
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
 
static final String DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF"
 
static final String DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00"
 
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
 
static final float FONT_DEFAULT_SIZE = 14
 
static final int LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL
 
static final int LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL
 
static final int SCALING_SCALE_PROPORTIONALLY = 0
 
static final int SCALING_SCALE_TO_FIT = 1
 
static final int TYPEFACE_DEFAULT = 0
 
static final int TYPEFACE_SANSSERIF = 1
 
static final int TYPEFACE_SERIF = 2
 
static final int TYPEFACE_MONOSPACE = 3
 
static final int LENGTH_PREFERRED = -1
 
static final int LENGTH_FILL_PARENT = -2
 
static final int LENGTH_UNKNOWN = -3
 
static final int LENGTH_PERCENT_TAG = -1000
 
static final int TOAST_LENGTH_SHORT = 0
 
static final int TOAST_LENGTH_LONG = 1
 
static final int DIRECTION_NORTH = 1
 
static final int DIRECTION_NORTHEAST = 2
 
static final int DIRECTION_EAST = 3
 
static final int DIRECTION_SOUTHEAST = 4
 
static final int DIRECTION_SOUTH = -1
 
static final int DIRECTION_SOUTHWEST = -2
 
static final int DIRECTION_WEST = -3
 
static final int DIRECTION_NORTHWEST = -4
 
static final int DIRECTION_NONE = 0
 
static final int DIRECTION_MIN = -4
 
static final int DIRECTION_MAX = 4
 
static float SLIDER_MIN_VALUE = 10
 
static float SLIDER_MAX_VALUE = 50
 
static float SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = ""
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = ""
 
- Protected Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
 AndroidNonvisibleComponent (Form form)
 
- Protected Attributes inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
final Form form
 

Detailed Description

Non-visible component for storing and retrieving files. Use this component to write or read files on the device. The default behavior is to write files to the private data directory associated with the app. The Companion writes files to /sdcard/AppInventor/data for easy debugging. If the file path starts with a slash (/), then the file is created relative to /sdcard. For example, writing a file to /myFile.txt will write the file in /sdcard/myFile.txt.

Definition at line 53 of file File.java.

Constructor & Destructor Documentation

◆ File()

com.google.appinventor.components.runtime.File.File ( ComponentContainer  container)

Creates a new File component.

Parameters
containerthe Form that this component is contained in.

Definition at line 61 of file File.java.

Member Function Documentation

◆ AfterFileSaved()

void com.google.appinventor.components.runtime.File.AfterFileSaved ( String  fileName)

Event indicating that the contents of the file have been written.

Parameters
fileNamethe name of the written file

Definition at line 381 of file File.java.

◆ AppendToFile()

void com.google.appinventor.components.runtime.File.AppendToFile ( String  text,
String  fileName 
)

Appends text to the end of a file. Creates the file if it does not already exist. See the help text under SaveFile(String, String) for information about where files are written. On success, the AfterFileSaved(String) event will run.

@internaldoc Calls the Write function to write to the file asynchronously to prevent the UI from hanging when there is a large write.

Parameters
textthe text to be stored
fileNamethe file to which the text will be stored

Definition at line 112 of file File.java.

◆ Delete()

void com.google.appinventor.components.runtime.File.Delete ( final String  fileName)

Deletes a file from storage. Prefix the fileName{:.text.block} with / to delete a specific file in the SD card (for example, /myFile.txt will delete the file /sdcard/myFile.txt). If the fileName{:.text.block} does not begin with a /, then the file located in the program's private storage will be deleted. Starting the fileName{:.text.block} with // is an error because asset files cannot be deleted.

Parameters
fileNamethe file to be deleted

Definition at line 191 of file File.java.

◆ GotText()

void com.google.appinventor.components.runtime.File.GotText ( String  text)

Event indicating that the contents from the file have been read.

Parameters
textread from the file

Definition at line 370 of file File.java.

◆ ReadFrom()

void com.google.appinventor.components.runtime.File.ReadFrom ( final String  fileName)

Reads text from a file in storage. Prefix the fileName{:.text.block} with / to read from a specific file on the SD card (for example, /myFile.txt will read the file /sdcard/myFile.txt). To read assets packaged with an application (also works for the Companion) start the fileName{:.text.block} with // (two slashes). If a fileName{:.text.block} does not start with a slash, it will be read from the application's private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.

Parameters
fileNamethe file from which the text is read

Definition at line 136 of file File.java.

◆ SaveFile()

void com.google.appinventor.components.runtime.File.SaveFile ( String  text,
String  fileName 
)

Saves text to a file. If the fileName{:.text.block} begins with a slash (/) the file is written to the sdcard (for example, writing to /myFile.txt will write the file to /sdcard/myFile.txt). If the fileName{:.text.block} does not start with a slash, it will be written in the program's private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging.

Note that this block will overwrite a file if it already exists. If you want to add content to an existing file use the AppendToFile(String, String) method.

@internaldoc Calls the Write function to write to the file asynchronously to prevent the UI from hanging when there is a large write.

Parameters
textthe text to be stored
fileNamethe file to which the text will be stored

Definition at line 91 of file File.java.


The documentation for this class was generated from the following file: