如何从android手机中获取联系人号码?
在我的应用程序中,我想显示手机上的所有联系人号码。我写的代码。但它不起作用。请任何人帮帮我。 这是我的代码:如何从android手机中获取联系人号码?,android,android-fragments,android-contacts,Android,Android Fragments,Android Contacts,在我的应用程序中,我想显示手机上的所有联系人号码。我写的代码。但它不起作用。请任何人帮帮我。 这是我的代码: public class MobileFragment extends Fragment{ iv_contacts = (ImageView) rootView.findViewById(R.id.iv_contacts); ic_contacts.setOnClickListener(new View.OnClickListener() { @Overr
public class MobileFragment extends Fragment{
iv_contacts = (ImageView) rootView.findViewById(R.id.iv_contacts);
ic_contacts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
browseContacts();
}
});
}
private void browseContacts() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK,
Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == getActivity().RESULT_OK) {
Uri contactUri = data.getData();
String[] projection = { Phone.NUMBER };
Cursor cursor = getActivity().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);
number = number.replace(" ", "");
}
}
}
这里我的onActivity结果没有调用我的片段。请显示您的代码,我将显示我的代码。请帮帮我。我从一周开始尝试此功能请任何人帮助我胜过任何人回复我…请帮助我我想我迟到了,但您的活动中是否也有OnActivityResult?