public static final class ContactsContract.Authorization extends Object
API for obtaining a pre-authorized version of a URI that normally requires special
permission (beyond READ_CONTACTS) to read. The caller obtaining the pre-authorized URI
must already have the necessary permissions to access the URI; otherwise a
SecurityException
will be thrown. Unlike Context.grantUriPermission(java.lang.String, android.net.Uri, int)
,
this can be used to grant permissions that aren't explicitly required for the URI inside
AndroidManifest.xml. For example, permissions that are only required when reading URIs
that refer to the user's profile.
The authorized URI returned in the bundle contains an expiring token that allows the caller to execute the query without having the special permissions that would normally be required. The token expires in five minutes.
This API does not access disk, and should be safe to invoke from the UI thread.
Example usage:
Uri profileUri = ContactsContract.Profile.CONTENT_VCARD_URI; Bundle uriBundle = new Bundle(); uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri); Bundle authResponse = getContext().getContentResolver().call( ContactsContract.AUTHORITY_URI, ContactsContract.Authorization.AUTHORIZATION_METHOD, null, // String arg, not used. uriBundle); if (authResponse != null) { Uri preauthorizedProfileUri = (Uri) authResponse.getParcelable( ContactsContract.Authorization.KEY_AUTHORIZED_URI); // This pre-authorized URI can be queried by a caller without READ_PROFILE // permission. }
Modifier and Type | Field and Description |
---|---|
static String |
AUTHORIZATION_METHOD
The method to invoke to create a pre-authorized URI out of the input argument.
|
static String |
KEY_AUTHORIZED_URI
The key to retrieve from the returned Bundle to obtain the pre-authorized URI.
|
static String |
KEY_URI_TO_AUTHORIZE
The key to set in the outbound Bundle with the URI that should be authorized.
|
Constructor and Description |
---|
Authorization() |
public static final String AUTHORIZATION_METHOD
public static final String KEY_URI_TO_AUTHORIZE
public static final String KEY_AUTHORIZED_URI