Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- btngetContact.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent1 = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
- ((Activity)context). startActivityForResult(intent1, RESULT_PICK_CONTACT);
- }
- });
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- Toast.makeText(context, "hiiii", Toast.LENGTH_SHORT).show();
- if(resultCode==RESULT_OK)
- {
- switch (requestCode) {
- case RESULT_PICK_CONTACT:
- getSelectedContact (data);
- break;
- }
- }
- else
- {
- Toast.makeText(context, "Faild", Toast.LENGTH_SHORT).show();
- }
- }
- private void getSelectedContact(Intent data) {
- Cursor cursor = null;
- try {
- String phoneNo = null;
- Uri uri = data.getData ();
- cursor = ((Activity)context).getContentResolver ().query (uri, null, null,null,null);
- cursor.moveToFirst ();
- int phoneIndex = cursor.getColumnIndex (ContactsContract.CommonDataKinds.Phone.NUMBER);
- phoneNo = cursor.getString (phoneIndex);
- phone.setText (phoneNo);
- } catch (Exception e) {
- e.printStackTrace ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement