Package android.content
Class ContextWrapper
- java.lang.Object
-
- android.content.Context
-
- android.content.ContextWrapper
-
public class ContextWrapper extends Context
Proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class android.content.Context
Context.BindServiceFlags
-
-
Field Summary
-
Fields inherited from class android.content.Context
BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_FOREGROUND_SERVICE, BIND_FOREGROUND_SERVICE_WHILE_AWAKE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE
-
-
Constructor Summary
Constructors Constructor Description ContextWrapper(Context base)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidattachBaseContext(Context base)Set the base context for this ContextWrapper.AssetManagergetAssets()Return an AssetManager instance for your application's package.ContextgetBaseContext()FilegetDatabasePath(String name)Returns the absolute path on the filesystem where a database created with#openOrCreateDatabaseis stored.FilegetFilesDir()Returns the absolute path to the directory on the filesystem where files created withContext.openFileOutput(java.lang.String, int)are stored.PackageManagergetPackageManager()Return PackageManager instance to find global package information.StringgetPackageName()Return the name of this application's package.ResourcesgetResources()Return a Resources instance for your application's package.FileOutputStreamopenFileOutput(String name, int mode)Open a private file associated with this Context's application package for writing.
-
-
-
Constructor Detail
-
ContextWrapper
public ContextWrapper(Context base)
-
-
Method Detail
-
attachBaseContext
protected void attachBaseContext(Context base)
Set the base context for this ContextWrapper. All calls will then be delegated to the base context. Throws IllegalStateException if a base context has already been set.- Parameters:
base- The new base context for this wrapper.
-
getBaseContext
public Context getBaseContext()
- Returns:
- the base context as set by the constructor or setBaseContext
-
getAssets
public AssetManager getAssets()
Description copied from class:ContextReturn an AssetManager instance for your application's package.
-
getResources
public Resources getResources()
Description copied from class:ContextReturn a Resources instance for your application's package.- Specified by:
getResourcesin classContext
-
getPackageManager
public PackageManager getPackageManager()
Description copied from class:ContextReturn PackageManager instance to find global package information.- Specified by:
getPackageManagerin classContext
-
getPackageName
public String getPackageName()
Description copied from class:ContextReturn the name of this application's package.- Specified by:
getPackageNamein classContext
-
openFileOutput
public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException
Description copied from class:ContextOpen a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.No permissions are required to invoke this method, since it uses internal storage.
- Specified by:
openFileOutputin classContext- Parameters:
name- The name of the file to open; can not contain path separators.mode- Operating mode. Use 0 orContext.MODE_PRIVATEfor the default operation,Context.MODE_APPENDto append to an existing file,Context.MODE_WORLD_READABLEandContext.MODE_WORLD_WRITEABLEto control permissions.- Returns:
- The resulting
FileOutputStream. - Throws:
FileNotFoundException- See Also:
Context.MODE_APPEND,Context.MODE_PRIVATE,Context.MODE_WORLD_READABLE,Context.MODE_WORLD_WRITEABLE,#openFileInput,#fileList,#deleteFile,FileOutputStream(String)
-
getFilesDir
public File getFilesDir()
Description copied from class:ContextReturns the absolute path to the directory on the filesystem where files created withContext.openFileOutput(java.lang.String, int)are stored.No permissions are required to read or write to the returned path, since this path is internal storage.
- Specified by:
getFilesDirin classContext- Returns:
- The path of the directory holding application files.
- See Also:
Context.openFileOutput(java.lang.String, int),#getFileStreamPath,#getDir
-
getDatabasePath
public File getDatabasePath(String name)
Description copied from class:ContextReturns the absolute path on the filesystem where a database created with#openOrCreateDatabaseis stored.- Specified by:
getDatabasePathin classContext- Parameters:
name- The name of the database for which you would like to get its path.- Returns:
- An absolute path to the given database.
- See Also:
#openOrCreateDatabase
-
-