Even if i choose a different contact name when i click my call button it displays the number of the first contact in my Contacts App. Foll is the code of my call button
calltheSuspect=(Button)view.findViewById(R.id.callthesuspect);
calltheSuspect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri phoneURI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER};
// String selection = ContactsContract.CommonDataKinds.Phone._ID + “= ?”;
// String[] selectionArgs = {Long.toString(crime.getPhoneId())};
Cursor c = getActivity().getContentResolver().query(phoneURI, projection, null, null, null);
int indexNumber = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
try {
if (c.getCount() == 0) {
return;
}
c.moveToFirst();
String phoneNumber = c.getString(indexNumber);
Uri call = Uri.parse("tel:" + phoneNumber);
Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
callNumber=Intent.createChooser(callNumber,"Call Number");
startActivity(callNumber);
} finally {
c.close();
}
}
});