2011-11-01 71 views

回答

1

我認爲你首先需要通過Contacts API訪問存儲在手機上的聯繫人。然後從聯繫人原始號碼中檢索電話號碼,並使用它發送您的短信。

2

這是可以做到如下:從電話簿

  1. 負載接觸(在button點擊或單擊EditText使用收集電話號碼)

//選取聯繫人點擊

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(reqCode, resultCode, data); 
    switch (reqCode) { 
     case (1) : 
      getContactInfo(data); 
      edittext.setText(contactName); // Set text on your EditText 
      break; 
    } 
} 
  1. 方法時,實際上得到所有日e contacts

當用戶單擊EditText時,將加載所有聯繫人。

public void getContactInfo(Intent intent) { 
    String phoneNumber = null; 
    String name = null; 

    Cursor cursor = managedQuery(intent.getData(), null, null, null, null); 
    while (cursor.moveToNext()) { 
     String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); 
     name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 

     String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 

     if (hasPhone.equalsIgnoreCase("1")) 
      hasPhone = "true"; 
     else 
      hasPhone = "false"; 

     if (Boolean.parseBoolean(hasPhone)) { 
      Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); 
      while (phones.moveToNext()) { 
       phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 

      }// end while 
      phones.close(); 
     }// end if 
    }// end while 
    return arr; 
}// end class 
+0

'返回arr'而'arr'沒有被定義,函數沒有返回類型。這是什麼? –

相關問題