Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android从电话簿导入联系人问题_Android_Android Contacts - Fatal编程技术网

Android从电话簿导入联系人问题

Android从电话簿导入联系人问题,android,android-contacts,Android,Android Contacts,我正在尝试从android电话簿导入联系人。该应用程序在所有手机上正常工作,但在HTC手机上失败。我的代码在下面 Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI); pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers star

我正在尝试从android电话簿导入联系人。该应用程序在所有手机上正常工作,但在HTC手机上失败。我的代码在下面

 Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
        pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
        startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);


Uri contactUri = data.getData();
                String[] projection = {Phone.DISPLAY_NAME,Phone.NUMBER};

                Cursor cursor = getContentResolver()
                        .query(contactUri, projection, null, null, null);
                cursor.moveToFirst();

                // Retrieve the phone number from the NUMBER column
                int column = cursor.getColumnIndex(Phone.NUMBER);
                int nameColumn=cursor.getColumnIndex(Phone.DISPLAY_NAME);
                String number = cursor.getString(column);
                String fName=cursor.getString(nameColumn);
                contact = new HashMap<String, String>();
                contact.put(fName, number);
                eName.setText(fName);
Intent pickContactIntent=新的Intent(Intent.ACTION\u PICK,Contacts.CONTENT\u URI);
pickContactIntent.setType(Phone.CONTENT_TYPE);//仅显示带有电话号码的用户联系人
startActivityForResult(选择联系人意向、选择联系人请求);
Uri contactUri=data.getData();
String[]projection={Phone.DISPLAY_NAME,Phone.NUMBER};
Cursor Cursor=getContentResolver()
.query(contactUri,projection,null,null,null);
cursor.moveToFirst();
//从“号码”列中检索电话号码
int column=cursor.getColumnIndex(Phone.NUMBER);
int NAME column=cursor.getColumnIndex(Phone.DISPLAY\u NAME);
字符串编号=cursor.getString(列);
String fName=cursor.getString(nameColumn);
contact=newhashmap();
联系人。put(fName,number);
eName.setText(fName);

由于是在客户端手机上,我无法查看日志。

Android对他们的联系人有几个抽象概念(联系人这是用户体验到的崩溃吗?可能是因为一些设备在没有姓名/号码的情况下,在显示号码名称时返回空值(如果设备有自定义内容提供商,如Skype等,可能会发生这种情况).有些设备返回显示名称中的数字,有些设备返回空值


或者只是用户看不到任何联系人?你知道用户是否真的有联系人吗?例如,如果联系人簿为空,你的代码会发生什么情况。

谢谢。我会尝试。我正在将意向传递给电话簿。用户拿起导入应用程序的联系人。感谢回复。是的,用户能够查看联系人,并选择了一个姓名和号码均为的联系人