public abstract class Context extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Context.BindServiceFlags |
| Modifier and Type | Field and Description |
|---|---|
static int |
BIND_ABOVE_CLIENT
Flag for
#bindService: indicates that the client application
binding to this service considers the service to be more important than
the app itself. |
static int |
BIND_ADJUST_WITH_ACTIVITY
Flag for
#bindService: If binding from an activity, allow the
target service's process importance to be raised based on whether the
activity is visible to the user, regardless whether another flag is
used to reduce the amount that the client process's overall importance
is used to impact it. |
static int |
BIND_ALLOW_OOM_MANAGEMENT
Flag for
#bindService: allow the process hosting the bound
service to go through its normal memory management. |
static int |
BIND_AUTO_CREATE
Flag for
#bindService: automatically create the service as long
as the binding exists. |
static int |
BIND_DEBUG_UNBIND
Flag for
#bindService: include debugging help for mismatched
calls to unbind. |
static int |
BIND_FOREGROUND_SERVICE |
static int |
BIND_FOREGROUND_SERVICE_WHILE_AWAKE |
static int |
BIND_IMPORTANT
Flag for
#bindService: this service is very important to
the client, so should be brought to the foreground process level
when the client is. |
static int |
BIND_NOT_FOREGROUND
Flag for
#bindService: don't allow this binding to raise
the target service's process to the foreground scheduling priority. |
static int |
BIND_NOT_VISIBLE
Flag for
#bindService: Don't consider the bound service to be
visible, even if the caller is visible. |
static int |
BIND_SHOWING_UI |
static int |
BIND_TREAT_LIKE_ACTIVITY |
static int |
BIND_VISIBLE |
static int |
BIND_WAIVE_PRIORITY
Flag for
#bindService: don't impact the scheduling or
memory management priority of the target service's hosting process. |
static int |
MODE_APPEND
File creation mode: for use with
openFileOutput(java.lang.String, int), if the file
already exists then write data to the end of the existing file
instead of erasing it. |
static int |
MODE_ENABLE_WRITE_AHEAD_LOGGING
Database open flag: when set, the database is opened with write-ahead
logging enabled by default.
|
static int |
MODE_MULTI_PROCESS
Deprecated.
MODE_MULTI_PROCESS does not work reliably in
some versions of Android, and furthermore does not provide any
mechanism for reconciling concurrent modifications across
processes. Applications should not attempt to use it. Instead,
they should use an explicit cross-process data management
approach such as
ContentProvider. |
static int |
MODE_PRIVATE
File creation mode: the default mode, where the created file can only
be accessed by the calling application (or all applications sharing the
same user ID).
|
static int |
MODE_WORLD_READABLE
Deprecated.
Creating world-readable files is very dangerous, and likely
to cause security holes in applications. It is strongly discouraged;
instead, applications should use more formal mechanism for interactions
such as
ContentProvider, BroadcastReceiver, and
android.app.Service. There are no guarantees that this
access mode will remain on a file, such as when it goes through a
backup and restore.
File creation mode: allow all other applications to have read access
to the created file. |
static int |
MODE_WORLD_WRITEABLE
Deprecated.
Creating world-writable files is very dangerous, and likely
to cause security holes in applications. It is strongly discouraged;
instead, applications should use more formal mechanism for interactions
such as
ContentProvider, BroadcastReceiver, and
android.app.Service. There are no guarantees that this
access mode will remain on a file, such as when it goes through a
backup and restore.
File creation mode: allow all other applications to have write access
to the created file. |
| Constructor and Description |
|---|
Context() |
| Modifier and Type | Method and Description |
|---|---|
abstract AssetManager |
getAssets()
Return an AssetManager instance for your application's package.
|
abstract File |
getDatabasePath(String name)
Returns the absolute path on the filesystem where a database created with
#openOrCreateDatabase is stored. |
abstract File |
getFilesDir()
Returns the absolute path to the directory on the filesystem where
files created with
openFileOutput(java.lang.String, int) are stored. |
abstract PackageManager |
getPackageManager()
Return PackageManager instance to find global package information.
|
abstract String |
getPackageName()
Return the name of this application's package.
|
abstract Resources |
getResources()
Return a Resources instance for your application's package.
|
abstract FileOutputStream |
openFileOutput(String name,
int mode)
Open a private file associated with this Context's application package
for writing.
|
public static final int MODE_PRIVATE
@Deprecated public static final int MODE_WORLD_READABLE
ContentProvider, BroadcastReceiver, and
android.app.Service. There are no guarantees that this
access mode will remain on a file, such as when it goes through a
backup and restore.
File creation mode: allow all other applications to have read access
to the created file.MODE_PRIVATE,
MODE_WORLD_WRITEABLE,
Constant Field Values@Deprecated public static final int MODE_WORLD_WRITEABLE
ContentProvider, BroadcastReceiver, and
android.app.Service. There are no guarantees that this
access mode will remain on a file, such as when it goes through a
backup and restore.
File creation mode: allow all other applications to have write access
to the created file.MODE_PRIVATE,
MODE_WORLD_READABLE,
Constant Field Valuespublic static final int MODE_APPEND
openFileOutput(java.lang.String, int), if the file
already exists then write data to the end of the existing file
instead of erasing it.@Deprecated public static final int MODE_MULTI_PROCESS
ContentProvider.This was the legacy (but undocumented) behavior in and before Gingerbread (Android 2.3) and this flag is implied when targetting such releases. For applications targetting SDK versions greater than Android 2.3, this flag must be explicitly set if desired.
#getSharedPreferences,
Constant Field Valuespublic static final int MODE_ENABLE_WRITE_AHEAD_LOGGING
#openOrCreateDatabase(String, int, CursorFactory),
#openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler),
SQLiteDatabase#enableWriteAheadLogging,
Constant Field Valuespublic static final int BIND_AUTO_CREATE
#bindService: automatically create the service as long
as the binding exists. Note that while this will create the service,
its android.app.Service#onStartCommand
method will still only be called due to an
explicit call to #startService. Even without that, though,
this still provides you with access to the service object while the
service is created.
Note that prior to android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH,
not supplying this flag would also impact how important the system
consider's the target service's process to be. When set, the only way
for it to be raised was by binding from a service in which case it will
only be important when that activity is in the foreground. Now to
achieve this behavior you must explicitly supply the new flag
BIND_ADJUST_WITH_ACTIVITY. For compatibility, old applications
that don't specify BIND_AUTO_CREATE will automatically have
the flags BIND_WAIVE_PRIORITY and
BIND_ADJUST_WITH_ACTIVITY set for them in order to achieve
the same result.
public static final int BIND_DEBUG_UNBIND
#bindService: include debugging help for mismatched
calls to unbind. When this flag is set, the callstack of the following
#unbindService call is retained, to be printed if a later
incorrect unbind call is made. Note that doing this requires retaining
information about the binding that was made for the lifetime of the app,
resulting in a leak -- this should only be used for debugging.public static final int BIND_NOT_FOREGROUND
#bindService: don't allow this binding to raise
the target service's process to the foreground scheduling priority.
It will still be raised to at least the same memory priority
as the client (so that its process will not be killable in any
situation where the client is not killable), but for CPU scheduling
purposes it may be left in the background. This only has an impact
in the situation where the binding client is a foreground process
and the target service is in a background process.public static final int BIND_ABOVE_CLIENT
#bindService: indicates that the client application
binding to this service considers the service to be more important than
the app itself. When set, the platform will try to have the out of
memory killer kill the app before it kills the service it is bound to, though
this is not guaranteed to be the case.public static final int BIND_ALLOW_OOM_MANAGEMENT
#bindService: allow the process hosting the bound
service to go through its normal memory management. It will be
treated more like a running service, allowing the system to
(temporarily) expunge the process if low on memory or for some other
whim it may have, and being more aggressive about making it a candidate
to be killed (and restarted) if running for a long time.public static final int BIND_WAIVE_PRIORITY
#bindService: don't impact the scheduling or
memory management priority of the target service's hosting process.
Allows the service's process to be managed on the background LRU list
just like a regular application process in the background.public static final int BIND_IMPORTANT
#bindService: this service is very important to
the client, so should be brought to the foreground process level
when the client is. Normally a process can only be raised to the
visibility level by a client, even if that client is in the foreground.public static final int BIND_ADJUST_WITH_ACTIVITY
#bindService: If binding from an activity, allow the
target service's process importance to be raised based on whether the
activity is visible to the user, regardless whether another flag is
used to reduce the amount that the client process's overall importance
is used to impact it.public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE
public static final int BIND_FOREGROUND_SERVICE
public static final int BIND_TREAT_LIKE_ACTIVITY
public static final int BIND_VISIBLE
public static final int BIND_SHOWING_UI
public static final int BIND_NOT_VISIBLE
#bindService: Don't consider the bound service to be
visible, even if the caller is visible.public abstract AssetManager getAssets()
public abstract Resources getResources()
public abstract PackageManager getPackageManager()
public abstract String getPackageName()
public abstract FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException
No permissions are required to invoke this method, since it uses internal storage.
name - The name of the file to open; can not contain path
separators.mode - Operating mode. Use 0 or MODE_PRIVATE for the
default operation, MODE_APPEND to append to an existing file,
MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control
permissions.FileOutputStream.FileNotFoundExceptionMODE_APPEND,
MODE_PRIVATE,
MODE_WORLD_READABLE,
MODE_WORLD_WRITEABLE,
#openFileInput,
#fileList,
#deleteFile,
FileOutputStream(String)public abstract File getFilesDir()
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.
openFileOutput(java.lang.String, int),
#getFileStreamPath,
#getDirpublic abstract File getDatabasePath(String name)
#openOrCreateDatabase is stored.name - The name of the database for which you would like to get
its path.#openOrCreateDatabase