i dont know how to do it
mCallButton=v.findViewById(R.id.call_button);
mCallButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Uri call = Uri.parse("tel:" + mCrime.getNumber());
Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
startActivity(callNumber);
}
});
mSuspectButton=v.findViewById(R.id.crime_suspect);
mSuspectButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pickContact.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContact,REQUEST_CONTACT);
}
});
public void onActivityResult(int requestCode,int resultCode,Intent data)
{
if(resultCode!= Activity.RESULT_OK)
{
return;
}
if (requestCode==REQUEST_DATE)
{
Date date=(Date)data.getSerializableExtra(DatePickerFragment.EXTRA_DATE);
mCrime.setDate(date);
updateDate();
}
if (requestCode == REQUEST_TIME) {
Date time = (Date) data.getSerializableExtra(TimePickerFragment.EXTRA_TIME);
mCrime.setTime(time);
updateTime();
}
else if (requestCode==REQUEST_CONTACT&&data!=null)
{
Uri contactUri=data.getData();
String[] queryFields=new String[]{ContactsContract.Contacts.DISPLAY_NAME};
Cursor c=getActivity().getContentResolver().query(contactUri,queryFields,null,null,null);
try {
if(c.getCount()==0){
return;
}
c.moveToFirst();
String suspect=c.getString(0);
mCrime.setSuspect(suspect);
mSuspectButton.setText(suspect);
}finally {
c.close();
}
Uri contactUri1= data.getData();
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor cursor = getActivity().getContentResolver().query(contactUri1, projection,
null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String number = cursor.getString(numberIndex);
mCrime.setNumber(number);
}
}
}
1 Like
This is my solution …