2011-05-23 194 views
0

我正在編寫搜索聯繫人和撥打電話的代碼。我的代碼可以列出聯繫人姓名並選擇特定的聯繫人。但是,當我撥打該選定的聯繫人時,它會說出所選的姓名,但會撥打聯繫人列表中的名字。任何人都可以通過從聯繫人列表中選擇姓名來幫助我編寫用於撥打特定號碼的代碼。 在此先感謝。爲什麼總是撥打第一個號碼..!

這裏是我用來搜索特定聯繫號碼的代碼。但選擇第一個數字。

private void populateContacts() 
{ 

    ContentResolver cr = getContentResolver(); 

    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 

    if (cur.getCount() > 0) { 

    while (cur.moveToNext()) 
    { 

     // ID AND NAME FROM CONTACTS CONTRACTS 
     id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); 

     // GET PHONE NUMBERS WITH QUERY STRING 
     if (Integer.parseInt(cur .getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { 

     Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID 
         + " = ?", new String[] { id }, null); 

     // WHILE WE HAVE CURSOR GET THE PHONE NUMERS 
     while (pCur.moveToNext()) 
     { 

       name = cur .getString(cur .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));  

      Log.i("jni", "ID :" + id); 
      Log.i("jni", "NAME :" + name); 

       // Do something with phones 
       //int phoneColumn = pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA); 
       //  number =pCur.getString(phoneColumn); 

      phone = pCur.getString(pCur .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA)); 

      Contacts.add(name+ phone ); 
     } 

    } 
    //  pCur.close(); 

} 
+1

您需要向我們提供一些代碼。 – 2011-05-23 11:18:40

+0

亞理查德施耐德告訴我們,這還不足以分析問題 – Karthik 2011-05-24 03:33:58

回答

0

您應該指定更多信息以便我們能夠幫助您。但是

您應該使用People Content Provider android.provider.Contacts.Phones.CONTENT_URI。 檢查此信息http://developer.android.com/guide/topics/providers/content-providers.html,你就能知道如何做到這一點;)

有關於使用聯繫人內容提供商,你會看到有他們是如何篩選特定的聯繫,並得到他們的信息內容提供者的解釋