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.
| |||||||||||
Check both a Uri and normal permission.
| |||||||||||
Determine whether a particular process and user ID has been granted
permission to access a specific URI.
| |||||||||||
Returns the list of intents that were broadcast since the last call to this method.
| |||||||||||
Return a ContentResolver instance for your application's package.
| |||||||||||
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.
|
[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 its 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 an BroadcastReceiver component. A pattern you can use to communicate from an 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 an 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. |
flags | Operation options for the binding. May be 0 or BIND_AUTO_CREATE. |
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 acess, 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. |
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. |
Returns the list of intents that were broadcast since the last call to this method.
Return a ContentResolver instance for your application's package.
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:
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.
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. |