【问题标题】:how to open native contact card by URI如何通过URI打开本机联系人卡片
【发布时间】:2013-02-03 15:43:15
【问题描述】:

有人可以解释一下如何为特定联系人 URi 打开联系人本机

我设法通过以下方式解析联系人 URI:

Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(displayName));

然后我尝试这样做:

     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
     intent.putExtra(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, "555");
     context.startActivity(intent);

但它只是打开本机通讯录而没有任何解析

【问题讨论】:

    标签: android android-intent contactscontract


    【解决方案1】:
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
    context.startActivity(intent);
    

    您可以使用contentResolver浏览来检索contactId:

    id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
    name = cur.getString( cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    Log.d(tag, "Id: "+ id+"\t Name: "+name);
    

    【讨论】:

      【解决方案2】:

      在获取联系人的cursor 和特定联系人的索引后,获取Uri 并以ACTION_VIEW 的意图开始活动,如下所示:

      cursor.moveToPosition(position); // or cursor.moveToFirst() if single contact was selected.
      long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID));
      String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(ContactsContract.Contacts.getLookupUri(id, lookupKey));
      try {
          context.startActivity(intent);
      } catch (Exception e) {
          e.printStackTrace();
      }
      

      【讨论】:

        猜你喜欢
        • 2014-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多