2011-07-07 51 views

回答

0

我不得不在學校爲我的學校做類似的事情。這裏是我結束了:

private List<String> emailAdresses; 

private List<String> readEmailAdresses() { 
     if(emailAdresses == null) 
      emailAdresses = new ArrayList<String>(); 

     try { 
      String emailAdress = null; 
      Cursor emailCursor = managedQuery(
        ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
        new String[] { Email.CONTACT_ID, Email.DATA1 }, null, null, 
        Email.CONTACT_ID); 

      while (emailCursor.moveToNext()) { 
       emailAdress = emailCursor.getString(emailCursor 
         .getColumnIndex(Email.DATA1)); 
       emailAdresses.add(emailAdress); 
      } 
     } catch (Exception ex) { 
      Log.e(TAG, "Retreive failed", ex); 
     } 

     return emailAdresses; 
    } 

只要確保你使用這個權限的例子:

<uses-permission android:name="android.permission.READ_CONTACTS" /> 
+0

@xstudio你使這u必須編寫的代碼2類??? – User

+0

我更新了我的答案,這提供了示例代碼,其餘部分由您決定。 Google是你的朋友。 –

相關問題