本文介绍了如何获得从手机通讯录中的联系人列表组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  btngal.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(查看为arg0){
                // TODO自动生成方法存根
                意图I =新意图(Intent.ACTION_PICK,android.provider.ContactsContract.Contacts.CONTENT_GROUP_URI);
                startActivityForResult(I,0);
            }
        });    }    @覆盖
    保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
        // super.onActivityResult(要求code,结果code,数据);
        如果(结果code!= RESULT_CANCELED){
            如果(要求code == 0){
                乌里selectContact = data.getData();
                的String [] = filePathColumn {Contacts.CONTENT_URI.toString()};
                光标光标= getContentResolver()查询(selectContact,
                        filePathColumn,NULL,NULL,NULL);
                cursor.moveToFirst();                INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
             文件路径= cursor.getString(参数:columnIndex);
                cursor.close();            }
        }    }

在做这个动作我得到以下错误:

  android.content.ActivityNotFoundException:无活动处理意向{行动= android.intent.action.PICK DAT =内容://com.android.contacts/contacts/group}


解决方案

为了读取原生的Andr​​oid应用中的联系人,你需要的权限,这样在你的manifest.xml

 <使用许可权的android:NAME =android.permission.READ_CONTACTS/>

请确保您有一个。

btngal.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent i=new Intent(Intent.ACTION_PICK,android.provider.ContactsContract.Contacts.CONTENT_GROUP_URI);
                startActivityForResult(i,0);        
            }
        }); 

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_CANCELED) {
            if (requestCode == 0) {
                Uri selectContact=data.getData();
                String[] filePathColumn={Contacts.CONTENT_URI.toString()};
                Cursor cursor = getContentResolver().query(selectContact,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
             filePath = cursor.getString(columnIndex);
                cursor.close();

            }
        }

    }

While doing this action I am getting below error:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://com.android.contacts/contacts/group }
解决方案

In order to read contacts from native android app, you need permission, like this in your manifest.xml

<uses-permission android:name="android.permission.READ_CONTACTS"/>

Make sure you have that one.

这篇关于如何获得从手机通讯录中的联系人列表组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 08:09