Created
October 22, 2019 15:45
-
-
Save BurningDroid/46ad09e5c970347b4424dff25c3680f0 to your computer and use it in GitHub Desktop.
[Android] startActivityForResult 사용 시 주의할 점 code 3
This file contains hidden or 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
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| // Check which request it is that we're responding to | |
| if (requestCode == PICK_CONTACT_REQUEST) { | |
| // Make sure the request was successful | |
| if (resultCode == RESULT_OK) { | |
| // Get the URI that points to the selected contact | |
| Uri contactUri = data.getData(); | |
| // We only need the NUMBER column, because there will be only one row in the result | |
| String[] projection = {Phone.NUMBER}; | |
| // Perform the query on the contact to get the NUMBER column | |
| // We don't need a selection or sort order (there's only one result for the given URI) | |
| // CAUTION: The query() method should be called from a separate thread to avoid blocking | |
| // your app's UI thread. (For simplicity of the sample, this code doesn't do that.) | |
| // Consider using CursorLoader to perform the query. | |
| Cursor cursor = getContentResolver() | |
| .query(contactUri, projection, null, null, null); | |
| cursor.moveToFirst(); | |
| // Retrieve the phone number from the NUMBER column | |
| int column = cursor.getColumnIndex(Phone.NUMBER); | |
| String number = cursor.getString(column); | |
| // Do something with the phone number... | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment