Android: Contact Picker Intent | Cannot instantiate the type Uri

前端 未结 2 531
傲寒
傲寒 2020-12-16 23:53

I am trying to pick contacts with phone number only.And I am following this code

static final int PICK_CONTACT_REQUEST = 1;  // The request code
...
private         


        
相关标签:
2条回答
  • 2020-12-17 00:49

    This works for me:

    private void pickContact() {
        Intent pickContactIntent = new Intent( Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI );
        pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
        startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
    }
    

    Edit:

    Your onActivityResult() should look like this:

    @Override
    public void onActivityResult( int requestCode, int resultCode, Intent intent ) {
    
        super.onActivityResult( requestCode, resultCode, intent );
        if ( requestCode == PICK_CONTACT_REQUEST ) {
    
            if ( resultCode == RESULT_OK ) {
                    Uri pickedPhoneNumber = intent.getData();
                    // handle the picked phone number in here.
                }
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-17 00:54

    Use Uri.parse() instead. You can't instsntiate a Uri directly

    0 讨论(0)
提交回复
热议问题