【问题标题】:Sim contacts won't show upSim 联系人不会显示
【发布时间】:2012-06-28 23:54:27
【问题描述】:

我刚刚创建了一个应用程序,当我按下一个按钮并检索所选联系人的号码时,我设法获取了电话联系人。

我的问题是我只能看到电话联系人,而不是 SIM 卡联系人。

我的代码是:

@Override
    public void onActivityResult(int reqCode, int resultCode, Intent data) {
        super.onActivityResult(reqCode, resultCode, data);
        if (resultCode!=0){
             Uri uri = data.getData();
             Cursor cursor=this.getContentResolver().query(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 ((Integer.parseInt(cursor.getString( cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)) { 
                             // You know have the number so now query it like this
             Cursor phones = getContentResolver().query( 
               ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
               null, 
               ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, 
                   null, null); 
                 while (phones.moveToNext()) { 

                  phoneNumber = phones.getString( 
                   phones.getColumnIndex( 
                      ContactsContract.CommonDataKinds.Phone.NUMBER));

                 } 
                 phonenumber.setText(phoneNumber);

                 phones.close(); 
                } 
              }

        }


    }

还有一些我无法理解的东西。

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); 开始活动(意图);

显示所有联系人,但我不能选择一个和结果

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

只显示手机中的联系人,这是为什么?

【问题讨论】:

标签: android android-contacts


【解决方案1】:

将此添加到您的意图中:

intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);

其他都很好。

【讨论】:

    猜你喜欢
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多