Android 当从列表中选择联系人时,从通讯簿中填充联系人号码有效,但从搜索结果中选择联系人时失败

Android 当从列表中选择联系人时,从通讯簿中填充联系人号码有效,但从搜索结果中选择联系人时失败,android,Android,我使用以下代码显示联系人列表,然后通过选择联系人来检索联系人号码。但是,在列表中搜索联系人然后从搜索结果中选择时,不会检索到任何号码。你知道我错过了什么吗?感谢您的帮助。谢谢你的阅读 private void registerLongClick() { TextView vonage_number = (TextView) findViewById(R.id.vonage_number); vonage_number.setOnLongClickListener

我使用以下代码显示联系人列表,然后通过选择联系人来检索联系人号码。但是,在列表中搜索联系人然后从搜索结果中选择时,不会检索到任何号码。你知道我错过了什么吗?感谢您的帮助。谢谢你的阅读

 private void registerLongClick() {
        TextView vonage_number = (TextView) findViewById(R.id.vonage_number);
        vonage_number.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                // Perform action on click
                    Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Phone.CONTENT_URI);  
                startActivityForResult(contactPickerIntent, 1001);
                            return true;
            }
        });
    }    

    @Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        String DEBUG_TAG = Constants.CALL_LOG_TAG_NAME;
            if (resultCode == RESULT_OK) {  
            switch (requestCode) {  
            case 1001:  
                Cursor cursor = null;  
                String phone = "";  
                try {  
                    Uri result = data.getData();  
                    Log.v(DEBUG_TAG, "Got a contact result: "  
                            + result.toString());  

                    // get the contact id from the Uri  
                    String id = result.getLastPathSegment();  

                    //query for phone number
                    cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,ContactsContract.CommonDataKinds.Phone._ID + " = " + id, null,
                            null);  

                    int phoneIdx = cursor.getColumnIndex(Phone.DATA);  

                    if (cursor.moveToFirst()) { 
                            phone = cursor.getString(phoneIdx);  
                        Log.v(DEBUG_TAG, "Got phone: " + phone);  
                    } else {  
                        Log.w(DEBUG_TAG, "No results");  
                    }  
                } catch (Exception e) {  
                    Log.e(DEBUG_TAG, "Failed to get phone data", e);  
                } finally {  
                    if (cursor != null) {  
                        cursor.close();  
                    }  
                    EditText phoneEntry = (EditText) findViewById(R.id.vonage_number);  
                    phoneEntry.setText(phoneEntry.getText().toString().trim()+phone);  
                    if (phone.length() == 0) {  
                        Toast.makeText(this, "No phone found for contact.",  
                                Toast.LENGTH_LONG).show();  
                    }  

                }  

                break;  
            }  

        } else {  
            Log.w(DEBUG_TAG, "Warning: activity result not ok");  
        }  
    }

为Try{}catch{}尝试以下操作

try {
Uri contactData = data.getData();  
Log.debug("Got a contact result: " + contactData.toString());  
Cursor lookupCursor =  managedQuery(contactData, null, null, null, null);
if (lookupCursor.moveToFirst()) {                                       
        String lookupKey = lookupCursor.getString(lookupCursor.getColumnIndexOrThrow(android.provider.ContactsContract.PhoneLookup.LOOKUP_KEY));
        Log.debug("Lookup key: " + lookupKey);

        cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY + " LIKE '" + lookupKey + "'", null, null);  
        startManagingCursor(cursor);

        if (cursor.moveToFirst()) {
                int phoneIdx = cursor.getColumnIndex(Phone.DATA);
                phone = cursor.getString(phoneIdx);  
                Log.debug("Got phone: " + phone); 
                cardNumber.setText(cardNumber.getText().toString().trim()+phone);  
                if (phone.length() == 0) {  
                    Toast.makeText(this, "No phone found for contact.", Toast.LENGTH_LONG).show();  
                }
        } 
        else {  
                Log.debug("No results");  
        } 
}  } catch (Exception e) {  
Log.error("Failed to get phone data:" + e.getMessage());  } 

当我长按Textfield时,这段代码显示地址列表,每个联系人的号码对应一行。然而,我刚刚意识到,当我在这个列表中搜索联系人时,搜索结果并没有显示所搜索联系人的所有号码。相反,它只显示联系人姓名。你知道怎么解决这个问题吗?