【问题标题】:Android Contact ListAndroid 联系人列表
【发布时间】:2010-12-26 05:16:06
【问题描述】:

任何人都可以阐明如何从 android 获取联系人列表吗?

我只想获得与拨号器应用程序中相同的列表。但是我使用下面的代码获得了很多不在拨号列表中的联系人。

ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Contacts.People.CONTENT_URI, null, null, null, Contacts.ContactMethods.DEFAULT_SORT_ORDER);
startManagingCursor(cursor);

提前致谢。

【问题讨论】:

    标签: android list contact


    【解决方案1】:

    你所拥有的似乎很好。您能否详细说明“获取大量不在拨号列表中的联系人”?是安卓在造人吗?还是您看到的人有电子邮件地址但没有电话号码(因此可能不会出现在拨号器中)?

    请注意,Contacts.People 适用于 Android 1.6 及更低版本。从 Android 2.0 开始,该提供程序已被弃用,取而代之的是 ContactsContract 提供程序集。

    【讨论】:

    • 我想很多开发者不会使用 ContactsContract 因为他们想要 1.6 的兼容性...
    【解决方案2】:

    嗯,先谢谢你的回答。只是为了阐明这一点。

    我只想为我手机上的联系人接收电子邮件。 “我的联系人”组。我看到这是 ContactList Activity 使用的组。

    我完成了这样的事情:

    c = cr.query(myGroupUri, mEmailsProjection, null, null, null);
    ....
    
    c.close();
    
    c = cr.query(
        Contacts.ContactMethods.CONTENT_URI,
            mContactsProjection, contactIds, null, null
    );
    ....
    c.close();
    

    只是先查询组,然后查询 emails 表。

    【讨论】:

      【解决方案3】:

      试试这个 sn-p:

      import android.app.ListActivity;
      import android.database.Cursor;
      import android.os.Bundle;
      import android.provider.ContactsContract;
      import android.provider.ContactsContract.CommonDataKinds.Phone;
      import android.widget.SimpleCursorAdapter;
      
      public class ContactList extends ListActivity {
          /** Called when the activity is first created. */
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
      
      
              Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER}, null, null, null);
      
              startManagingCursor(cursor);
      
              String[] from = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER};
      
              int[] to = new int[] { R.id.name_entry, R.id.number_entry};
      
              SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_entry, cursor, from, to);
              this.setListAdapter(adapter);
          }
      }
      

      XML 文件是:

      list_entry.xml

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:padding="6dip">
              <TextView
                  android:id="@+id/name_entry"
                  android:layout_width="fill_parent"
                  android:layout_height="0dip"
                  android:layout_weight="1"
                  android:gravity="center_vertical"
              android:textSize="18dip"/>
              <TextView
                  android:layout_width="fill_parent"
                  android:layout_height="0dip"
                  android:layout_weight="1"
                  android:id="@+id/number_entry"
                  android:singleLine="true"
                  android:ellipsize="marquee"
              android:textSize="18dip"/>
          </LinearLayout>
      

      【讨论】:

      • 需要 否则它很有用。
      • @KKD:应该用什么来代替它?
      【解决方案4】:

      This是android联系人列表Activity的基本实现。

      【讨论】:

        【解决方案5】:

        尝试使用意图转到联系人列表

                    startActivityForResult( new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI),1);}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-06-25
          • 2016-10-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-01-04
          相关资源
          最近更新 更多