Last active
March 31, 2020 18:54
-
-
Save amrro/8bf2f4ce7f8428098dbea9f9ea95caaf to your computer and use it in GitHub Desktop.
Pick contact ctonract from the official docs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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