Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取电子邮件,ID';联系人的s和电话(不使用活动)_Android_Javabeans_Android Context - Fatal编程技术网

Android 获取电子邮件,ID';联系人的s和电话(不使用活动)

Android 获取电子邮件,ID';联系人的s和电话(不使用活动),android,javabeans,android-context,Android,Javabeans,Android Context,我的类没有extends活动或onCreate()方法。因此,从将活动扩展到此类的类中传递上下文参数: public static void getContactNumbers(Context context) { String contactNumber = null; int contactNumberType = Phone.TYPE_MOBILE; String nameOfContact = null; Cont

我的类没有extends活动或
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();

    }

如何实现
ApplicationConstants
ContactNumberBean(ContactName of Contact,contactNumber,contactNumberType))
这两个类?

以下是几乎相同问题的解决方案-

希望有帮助:)