There is no Activity or onCreate() method in my class. Therefore, pass a context parameter from a class that extends Activity to this class:
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(); } } }
How can I implement ApplicationConstants and ContactNumberBean(nameOfContact, contactNumber, contactNumberType)) these two classes?
source share