I tried almost every other answer or Code out there but my problem still persists. The phone number getting retrieved of contacts are arbitrary 3-4 digit numbers and not the exact phone number of the contact. When i go ahead and dial the number it dials to "6855". Please help.
the code
if(mWasButtonClicked){
String[] projections = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER};
String selectionClause = ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?";
String[] selectionArgs = new String[] {mContactID};
Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,projections,selectionClause,selectionArgs,null,null);
try {
if(c.getCount() == 0){return;}
if(c!=null){
while(c.moveToNext()){
c.moveToFirst();
phoneNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.d("TEST",phoneNumber);
}
}
}finally {
c.close();
}
}
for the call button
mCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("tel:"+phoneNumber);
startActivity(new Intent(Intent.ACTION_CALL,uri));
}
});
For retrieving the contact ID
Uri content_uri = data.getData();
String[] projection = new String[] {ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.Contacts._ID};
Cursor c = getContentResolver().query(content_uri,projection,null,null,null,null);
try {
if(c.getCount() == 0){return;}
if(c!=null){
while(c.moveToNext()){
c.moveToFirst();
String name = c.getString(0);
mGetNameButton.setText(name);
mContactID = c.getString(1);
Log.d("TEST",mContactID);
}
}
}finally {
c.close();
}
and the logs
2020-01-10 05:41:38.284 27904-27904/com.example.contactsuri D/TEST: 84