2011-06-14 27 views
4

我的班級沒有擴展活動或onCreate()方法。因此,通過從類上下文參數延伸活動這個類:從聯繫人處獲取電子郵件,身份證號碼和電話(不使用活動)

public static void getContactNumbers(Context context) { 
     String contactNumber = null; 
     int contactNumberType = Phone.TYPE_MOBILE; 
     String nameOfContact = null; 

      ContentResolver cr = context.getContentResolver(); 
      Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, 
        null, null, null); 
      if (cur.getCount() > 0) { 
       while (cur.moveToNext()) { 
        String id = cur.getString(cur 
          .getColumnIndex(BaseColumns._ID)); 
        nameOfContact = cur 
          .getString(cur 
            .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 

        if (Integer 
          .parseInt(cur.getString(cur 
            .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { 
         Cursor phones = cr 
           .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
             null, 
             ContactsContract.CommonDataKinds.Phone.CONTACT_ID 
               + " = ?", new String[] { id }, 
             null); 

         while (phones.moveToNext()) { 
          contactNumber = phones.getString(phones 
            .getColumnIndex(Phone.NUMBER)); 
          contactNumberType = phones.getInt(phones 
            .getColumnIndex(Phone.TYPE)); 
          Log.i(TAG, "...Contact Name ...." + nameOfContact 
            + "...contact Number..." + contactNumber); 
          ApplicationConstants.phoneContacts 
            .add(new ContactNumberBean(nameOfContact, 
              contactNumber, contactNumberType)); 
         } 
         phones.close(); 
        } 

       } 
      }// end of contact name cursor 
      cur.close(); 

    } 

如何實現ApplicationConstantsContactNumberBean(nameOfContact, contactNumber, contactNumberType))這兩個類?

回答

1

這裏是解決幾乎同樣的問題 - Answer

希望它能幫助:)

相關問題