我有textview。點擊它打開本地聯繫人列表。一旦用戶選擇了一個聯繫人,我應該在我的應用程序中顯示該號碼。我可以顯示姓名但不能顯示號碼。請幫忙。Android: - 選擇聯繫人並致電至選定號碼
在此先感謝。
這是我的代碼,但選擇的接觸我的應用程序崩潰後的。「不幸的是‘APP_NAME’已停止」
public void dail(View v)
{
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (data != null) {
Uri uri = data.getData();
if (uri != null) {
Cursor c = null;
try {
c = getContentResolver().query(uri, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE },
null, null, null);
if (c != null && c.moveToFirst()) {
String number = c.getString(0);
int type = c.getInt(1);
showSelectedNumber(type, number);
}
} finally {
if (c != null) {
c.close();
}
}
}
}
}
public void showSelectedNumber(int type, String number) {
Toast.makeText(this, type + ": " + number, Toast.LENGTH_LONG).show();
}
}
哪裏是你的崩潰?聯繫人選擇的代碼在哪裏? – GrIsHu