java.lang.Object | |||
↳ | android.content.Context | ||
↳ | android.content.ContextWrapper | ||
↳ | android.test.IsolatedContext |
A mock context which prevents its users from talking to the rest of the device while stubbing enough methods to satify code that tries to talk to other packages.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.content.Context
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Connect to an application service, creating it if needed.
| |||||||||||
Determine whether a particular process and user ID has been granted
permission to access a specific URI.
| |||||||||||
Check both a Uri and normal permission.
| |||||||||||
Returns the list of intents that were broadcast since the last call to this method.
| |||||||||||
Return a ContentResolver instance for your application's package.
| |||||||||||
Returns the absolute path to the directory on the filesystem where
files created with
openFileOutput(String, int) are stored. | |||||||||||
Return the handle to a system-level service by name.
| |||||||||||
Register a BroadcastReceiver to be run in the main activity thread.
| |||||||||||
Broadcast the given intent to all interested BroadcastReceivers.
| |||||||||||
Broadcast the given intent to all interested BroadcastReceivers, delivering
them one at a time to allow more preferred receivers to consume the
broadcast before it is delivered to less preferred receivers.
| |||||||||||
Unregister a previously registered BroadcastReceiver.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.content.ContextWrapper
| |||||||||||
From class
android.content.Context
| |||||||||||
From class
java.lang.Object
|
Connect to an application service, creating it if needed. This defines a dependency between your application and the service. The given conn will receive the service object when it is created and be told if it dies and restarts. The service will be considered required by the system only for as long as the calling context exists. For example, if this Context is an Activity that is stopped, the service will not be required to continue running until the Activity is resumed.
This function will throw SecurityException
if you do not
have permission to bind to the given service.
Note: this method can not be called from a
BroadcastReceiver
component. A pattern you can use to
communicate from a BroadcastReceiver to a Service is to call
startService(Intent)
with the arguments containing the command to be
sent, with the service calling its
stopSelf(int)
method when done executing
that command. See the API demo App/Service/Service Start Arguments
Controller for an illustration of this. It is okay, however, to use
this method from a BroadcastReceiver that has been registered with
registerReceiver(BroadcastReceiver, IntentFilter)
, since the lifetime of this BroadcastReceiver
is tied to another object (the one that registered it).
service | Identifies the service to connect to. The Intent may
specify either an explicit component name, or a logical
description (action, category, etc) to match an
IntentFilter published by a service. |
---|---|
conn | Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null. |
flags | Operation options for the binding. May be 0,
BIND_AUTO_CREATE , BIND_DEBUG_UNBIND ,
BIND_NOT_FOREGROUND , BIND_ABOVE_CLIENT ,
BIND_ALLOW_OOM_MANAGEMENT , or
BIND_WAIVE_PRIORITY . |
true
is returned;
false
is returned if the connection is not made so you will not
receive the service object.Determine whether a particular process and user ID has been granted permission to access a specific URI. This only checks for permissions that have been explicitly granted -- if the given process/uid has more general access to the URI's content provider then this check will always fail.
uri | The uri that is being checked. |
---|---|
pid | The process ID being checked against. Must be > 0. |
uid | The user ID being checked against. A uid of 0 is the root user, which will pass every permission check. |
modeFlags | The type of access to grant. May be one or both of
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION . |
PERMISSION_GRANTED
if the given
pid/uid is allowed to access that uri, or
PERMISSION_DENIED
if it is not.Check both a Uri and normal permission. This allows you to perform
both checkPermission(String, int, int)
and checkUriPermission(Uri, int, int, int)
in one
call.
uri | The Uri whose permission is to be checked, or null to not do this check. |
---|---|
readPermission | The permission that provides overall read access, or null to not do this check. |
writePermission | The permission that provides overall write access, or null to not do this check. |
pid | The process ID being checked against. Must be > 0. |
uid | The user ID being checked against. A uid of 0 is the root user, which will pass every permission check. |
modeFlags | The type of access to grant. May be one or both of
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION . |
PERMISSION_GRANTED
if the caller
is allowed to access that uri or holds one of the given permissions, or
PERMISSION_DENIED
if it is not.
Returns the list of intents that were broadcast since the last call to this method.
Return a ContentResolver instance for your application's package.
Returns the absolute path to the directory on the filesystem where
files created with openFileOutput(String, int)
are stored.
No permissions are required to read or write to the returned path, since this path is internal storage.
Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are:
WINDOW_SERVICE
("window")
WindowManager
.
LAYOUT_INFLATER_SERVICE
("layout_inflater")
LayoutInflater
for inflating layout resources
in this context.
ACTIVITY_SERVICE
("activity")
ActivityManager
for interacting with the
global activity state of the system.
POWER_SERVICE
("power")
PowerManager
for controlling power
management.
ALARM_SERVICE
("alarm")
AlarmManager
for receiving intents at the
time of your choosing.
NOTIFICATION_SERVICE
("notification")
NotificationManager
for informing the user
of background events.
KEYGUARD_SERVICE
("keyguard")
KeyguardManager
for controlling keyguard.
LOCATION_SERVICE
("location")
LocationManager
for controlling location
(e.g., GPS) updates.
SEARCH_SERVICE
("search")
SearchManager
for handling search.
VIBRATOR_SERVICE
("vibrator")
Vibrator
for interacting with the vibrator
hardware.
CONNECTIVITY_SERVICE
("connection")
ConnectivityManager
for
handling management of network connections.
WIFI_SERVICE
("wifi")
WifiManager
for management of
Wi-Fi connectivity.
WIFI_P2P_SERVICE
("wifip2p")
WifiP2pManager
for management of
Wi-Fi Direct connectivity.
INPUT_METHOD_SERVICE
("input_method")
InputMethodManager
for management of input methods.
UI_MODE_SERVICE
("uimode")
UiModeManager
for controlling UI modes.
DOWNLOAD_SERVICE
("download")
DownloadManager
for requesting HTTP downloads
BATTERY_SERVICE
("batterymanager")
BatteryManager
for managing battery state
JOB_SCHEDULER_SERVICE
("taskmanager")
JobScheduler
for managing scheduled tasks
Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)
name | The name of the desired service. |
---|
Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
The system may broadcast Intents that are "sticky" -- these stay around after the broadcast as finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your receiver as if it had just been broadcast.
There may be multiple sticky Intents that match filter, in which case each of these will be sent to receiver. In this case, only one of these can be returned directly by the function; which of these that is returned is arbitrarily decided by the system.
If you know the Intent your are registering for is sticky, you can supply null for your receiver. In this case, no receiver is registered -- the function simply returns the sticky Intent that matches filter. In the case of multiple matches, the same rules as described above apply.
See BroadcastReceiver
for more information on Intent broadcasts.
As of ICE_CREAM_SANDWICH
, receivers
registered with this method will correctly respect the
setPackage(String)
specified for an Intent being broadcast.
Prior to that, it would be ignored and delivered to all matching registered
receivers. Be careful if using this for security.
Note: this method cannot be called from a
BroadcastReceiver
component; that is, from a BroadcastReceiver
that is declared in an application's manifest. It is okay, however, to call
this method from another BroadcastReceiver that has itself been registered
at run time with registerReceiver(BroadcastReceiver, IntentFilter)
, since the lifetime of such a
registered BroadcastReceiver is tied to the object that registered it.
receiver | The BroadcastReceiver to handle the broadcast. |
---|---|
filter | Selects the Intent broadcasts to be received. |
Broadcast the given intent to all interested BroadcastReceivers. This
call is asynchronous; it returns immediately, and you will continue
executing while the receivers are run. No results are propagated from
receivers and receivers can not abort the broadcast. If you want
to allow receivers to propagate results or abort the broadcast, you must
send an ordered broadcast using
sendOrderedBroadcast(Intent, String)
.
See BroadcastReceiver
for more information on Intent broadcasts.
intent | The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
---|
Broadcast the given intent to all interested BroadcastReceivers, delivering them one at a time to allow more preferred receivers to consume the broadcast before it is delivered to less preferred receivers. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run.
See BroadcastReceiver
for more information on Intent broadcasts.
intent | The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
---|---|
receiverPermission | (optional) String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
Unregister a previously registered BroadcastReceiver. All filters that have been registered for this BroadcastReceiver will be removed.
receiver | The BroadcastReceiver to unregister. |
---|