Skip to content

Instantly share code, notes, and snippets.

@amrro
Last active March 31, 2020 18:54
Show Gist options
  • Save amrro/8bf2f4ce7f8428098dbea9f9ea95caaf to your computer and use it in GitHub Desktop.
Save amrro/8bf2f4ce7f8428098dbea9f9ea95caaf to your computer and use it in GitHub Desktop.
Pick contact ctonract from the official docs.
/**
* An {@link ActivityResultContract} to request the user to pick a contact from the contacts
* app.
* <p>
* The result is a {@code content:} {@link Uri}.
*
* @see ContactsContract
*/
public static final class PickContact extends ActivityResultContract<Void, Uri> {
@NonNull
@Override
public Intent createIntent(@NonNull Context context, @Nullable Void input) {
return new Intent(Intent.ACTION_PICK).setType(ContactsContract.Contacts.CONTENT_TYPE);
}
@Nullable
@Override
public Uri parseResult(int resultCode, @Nullable Intent intent) {
if (intent == null || resultCode != Activity.RESULT_OK) return null;
return intent.getData();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment