首页 > 解决方案 > onActivityResult not executed after contact picked

问题描述

after i choose a contact to display name and phone number via intent,onActivityResult is not executed.

I look for some answer here but nono have solved my problem.When i star to develop that function it worked but after some validations(if permission are granted) its stops working.

contact.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           if(GeneralUtility.validatePermission(context, Manifest.permission.READ_CONTACTS)){
               initPickContacts();
           }else{
               GeneralUtility.navigateSettingByApp(context);
               Toast.makeText(context, "Permiso no obtenido", Toast.LENGTH_SHORT).show();
           }
        }
    });

public void initPickContacts(){
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    startActivityForResult(intent, PICK_CONTACT_REQUEST);
    Intent i = new Intent(Intent.ACTION_PICK, 
    ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(i, PICK_CONTACT_REQUEST);
}

protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == PICK_CONTACT_REQUEST) {
        if (resultCode == RESULT_OK) {
            Uri contactUri = intent.getData();
            renderContact(contactUri);
        }
    }
}

I need to obtain the uri of the contact.

标签: javaandroid

解决方案


it works now. I changed the value of PICK_CONTACT_REQUEST to 1 and onActivityResult works.


推荐阅读