のすべての種類を取得するには(シングル)接触すべての連絡先を取得し、単一の接触名の数
イムは、単一の接触のすべてのタイプを持つすべての連絡先を取得し、私は成功しましたが、印刷のすべての種類を取得innerlist(複数の種類の電話番号が含まれている)、それは(例を読んでませんでした).....その単一の接触のためのinnerlistの大きさに応じてのために
例を最後に追加された連絡先を印刷
EX用:担当者名:NUMBERS 3 MobileでのABCタイプ:123、HOME:456、OFFICE:789ので、このコード
for (int i = 0; i < numberlist.size(); i++) { Log.e("inner", numberlist.get(i).getName() + " number " + numberlist.get(i).getNumber()); }
が(3回が、同じ連絡先番号)に印刷されます(内部、ABC番号789) ;
POJOクラス
public class ContactClass extends RealmObject {
@PrimaryKey
String id;
String name;
String number;
RealmList<ContactClass> numberlist;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public ContactClass() {
}
public RealmList<ContactClass> getNumberlist() {
return numberlist;
}
public void setNumberlist(RealmList<ContactClass> numberlist) {
this.numberlist = numberlist;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
結果、私は連絡先の名前と、その単一の名前の数字のすべての種類を保存したい
をしたいです..
コード私は接触が2つの以上の電話番号を持っている場合は、同じ連絡先の複数のContactClass
作成することがあります
public void loadContact() {
//swipeRefreshLayout.setRefreshing(true);
RealmList<ContactClass> list = new RealmList<>();
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
ContentResolver cr = getActivity().getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
RealmList<ContactClass> numberlist = new RealmList<>();
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
ContactClass contactClass = new ContactClass();
contactClass.setId(id);
contactClass.setName(name);
if (cur.getInt(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 (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
int type = pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
// Log.e("called", phoneNo + " " + name + " " + id);
switch (type) {
case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"home");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"mobile");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"work");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"eaxhome");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"faxwork");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_MAIN:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"main");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo + " name " + name+" type "+"home");
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo);
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_PAGER:
try {
if (phoneNo.equals("") || phoneNo != null) {
contactClass.setNumber(phoneNo);
Log.e("test", phoneNo);
numberlist.add(contactClass);
}
} catch (Exception e) {
Log.d(TAG, e.toString());
}
break;
}
}
pCur.close();
/* HashSet<ContactClass> h = new HashSet<>();
h.addAll(numberlist);
numberlist.clear();
numberlist.addAll(h);*/
contactClass.setNumberlist(numberlist);
list.add(contactClass);
for (int i = 0; i < numberlist.size(); i++) {
Log.e("inner", numberlist.get(i).getName() + " number " + numberlist.get(i).getNumber());
}
}//1637
}
// saveToRealm(list);
/* try {
HashSet hs = new HashSet();
hs.addAll(list); // demoArrayList= name of arrayList from which u want to remove duplicates
List<ContactClass> classList = new ArrayList<>();
list.clear();
classList.addAll(hs);
saveToRealm(classList);
Log.e("resize", classList.size() + "");
} catch (Exception e) {
Log.d("savetorealm", "catch " + e.toString());
}*/
}
}
uはそれのANSをplzは可能私は私の質問を更新しましたか? –