你好,游客 登录 注册 搜索
背景:
阅读新闻

Android选择联系人

[日期:2014-06-13] 来源:Linux社区  作者:iamshaofa [字体:大 中 小]

其实Android里没有难的技术,看它的文档就可了。下面算是直接从它的文档里抄的例子,稍微加点东西。

Android实现批量添加联系人到通讯录 http://www.linuxidc.com/Linux/2014-05/101853.htm

Android手机联系人数据库分析 http://www.linuxidc.com/Linux/2013-12/94346.htm

Android调用系统联系人返回联系人结果 http://www.linuxidc.com/Linux/2013-05/84294.htm

Android 由data 获取联系人信息 http://www.linuxidc.com/Linux/2013-04/82696.htm

Android使用Contact数据模型来批量插入联系人 http://www.linuxidc.com/Linux/2011-12/48574.htm
 
发出action请求

Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
 pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
 startActivityForResult(pickContactIntent, 11);

接收回复

 protected void onActivityResult(int requestCode, int resultCode, Intent data)
 {
  if(requestCode == 11 && resultCode == RESULT_OK)
  {
  Uri contactUri = data.getData();
            // We only need the NUMBER column, because there will be only one row in the result
           
      String[] projection = {
          ContactsContract.PhoneLookup.DISPLAY_NAME, 
                    ContactsContract.CommonDataKinds.Phone.NUMBER
                    }; 
        //String[] projection = {Phone.NUMBER};

            // Perform the query on the contact to get the NUMBER column
            // We don't need a selection or sort order (there's only one result for the given URI)
            // CAUTION: The query() method should be called from a separate thread to avoid blocking
            // your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
            // Consider using CursorLoader to perform the query.
            Cursor cursor = getContentResolver()
                    .query(contactUri, projection, null, null, null);
            cursor.moveToFirst();

            // Retrieve the phone number from the NUMBER column
            int indexPhoneNumber = cursor.getColumnIndex(Phone.NUMBER);
            int indexDisplayName = cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
            String phoneNumber = cursor.getString(indexPhoneNumber);
            String displayName = cursor.getString(indexDisplayName);

            if(phoneNumber != null && displayName != null)
            {
      if(phoneNumber.startsWith("+86"))
        phoneNumber = phoneNumber.substring(3);
     
      EditText textNumber = (EditText)findViewById(R.id.text_number);
      textNumber.setText("\"" + displayName + "\"" + phoneNumber);       
            }           
  }
 }

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-06/103108.htm

linux
相关资讯       Android联系人 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款