English 中文(简体)
只有在有电话号码时,才能获得所有联系人的姓名和电话号码?
原标题:How to get all contacts full name and phone number, only if they have a phone number?

我试图接触所有有电话号码的联络人,并记录他们的全名和电话号码(以及将来的联络照片),但我 st。 我的守则是:

String contacts = "";

    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null); 
    while (cursor.moveToNext()) {
       String contactId = cursor.getString(cursor.getColumnIndex( 
       ContactsContract.Contacts._ID)); 
       String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
       if (hasPhone == "1") {
           contacts += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ":" + "how to get number?" + "|";
       }
    }
    cursor.close();

优势 如联系人有电话号码,电话应包含“1”,然后在“联系”电话号码上添加该号码和电话号码。 即便如此, 电话中不含“1”,(从标识中抽取)在状况说明中没有任何代码。 此外,你如何获得电话号码,也没有任何联系。 联系次数。

最佳回答

为此:

if (Integer.parseInt(hasPhone) > 0) { 
    Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ contactId, null, null); 
    phones.moveToNext(); //if you are interested in all contact phones do a while()
    String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
    phones.close();
    contacts += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ":" + phoneNumber + "|";
}
问题回答

Change to:

hasPhone.equals("1")

= 操作者检查物体平等,也就是说,如果Phone人与明显错误的“1”相同。

你们想要检查色情平等,因此,你应当使用“平权”方法,对显示平等、意义、相互检查的两条物体进行比较,如果两者都具有相同的特性。

此外,考虑使用《眼光》,如下文所述:

如果你希望避免今后提及具体接触。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签