I'm trying to get phone number as string in android, I succeeded to get contact and get from him the phone number but the result in the logs is data1
and the number is 32821
. I don't get my problem.
Here is my code:
public void getContact(View view) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, 10);
}
Intent contactsIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
this.pickContact = 1;
startActivityForResult(contactsIntent, this.pickContact);
}
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if(reqCode == this.pickContact) {
if (resultCode == Activity.RESULT_OK) {
Log.d("ContactsH", "ResOK");
Uri contactData = data.getData();
Cursor contact = getContentResolver().query(contactData, null, null, null, null);
if (contact.moveToFirst()) {
String phoneNumber = ContactsContract.CommonDataKinds.Phone.NUMBER;
Log.d("ContactsH", "Calling to:"+phoneNumber);
contact.close();
this.callByNumber(phoneNumber);
}
}
} else {
Log.d("ContactsH", "Canceled");
}
}
Any help ?