public class EspContactStub
extends java.lang.Object
Stubbing contact request with Intent.ACTION_PICK.
Typical application starts the contact picker and use the reported Uri to access selected contact data by ContentResolver. With this stubs you can avoid the start of the contact picker and let them report your preferred data Uri. But you must provide the contact data on your phone by self.
Example usage:
// since Android M you need permissions to write contacts
EspPermissionsTool.ensurePermissions(currentActivity(), Manifest.permission.WRITE_CONTACTS)
// provide some test contact data
Uri contactUri = EspContactTool.uriByName("My Test User");
if(contactUri == null) {
contactUri = EspContactTool.spec().withDisplayName("My Test User").addContact();
}
// register a stub with your test contact uri
EspContactStub.register(contactUri);
// now perform action to start contact picker request
EspContactTool,
Base description for intent stubbing.| Constructor and Description |
|---|
EspContactStub() |
| Modifier and Type | Method and Description |
|---|---|
static void |
register(android.net.Uri contactDataUri)
Register new stub for contact data requests with
Activity.RESULT_OK. |
static void |
register(android.net.Uri contactDataUri,
int activityResult)
Register new stub for contact data requests with specific activity result.
|
static void |
register(android.net.Uri contactDataUri,
int activityResult,
org.hamcrest.Matcher<? super android.content.Intent> extraMatcher)
Register new stub for contact data requests with specific activity result and extra Intent matcher.
|
public static void register(android.net.Uri contactDataUri)
Register new stub for contact data requests with Activity.RESULT_OK.
contactDataUri - Contact uri which will be accessible as intent data.public static void register(android.net.Uri contactDataUri,
int activityResult)
Register new stub for contact data requests with specific activity result.
contactDataUri - Contact uri which will be accessible as intent data.activityResult - Activity.RESULT_OK or Activity.RESULT_CANCELED.public static void register(android.net.Uri contactDataUri,
int activityResult,
org.hamcrest.Matcher<? super android.content.Intent> extraMatcher)
Register new stub for contact data requests with specific activity result and extra Intent matcher.
contactDataUri - Contact uri which will be accessible as intent data.activityResult - Activity.RESULT_OK or Activity.RESULT_CANCELED.extraMatcher - Additional intent matcher to match specific requests.