尝试使用电子邮件地址取得联系_ID [英] Attempting to get contact _ID using email address

查看:184
本文介绍了尝试使用电子邮件地址取得联系_ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,与聚集接触_ids不是静态的,但可能会随时间而改变(见:的谷歌小组讨论)。

I know that with aggregation contact _ids are not static, but may change over time (see: Google Group Discussion).

所以,在我的应用我存储内容查找键,并选定联系人的电流id。

So, in my app I am storing the content lookup key and the current id of a selected contact.

我所试图做的是这样的:当消息从特定电子邮件地址进来,查询手机联系人,看看有没有从电子邮件地址与任何人联系,然后比较我的存储接触的接触先用我的存储的联系人_id和查找键,进入当前联系人_id做一个新的查询。

What I am trying to do is this: when a message comes in from a particular email address, query the phone contacts and see if that from email address is associated with any of them, and then compare that contact with my stored contact, first doing a fresh query using my stored contact _id and lookup key to get the current contact _id.

下面是我在尝试使用的电子邮件地址来查找联系人_id:

Here is how I am attempting to find the contact _id using the email address:

String[] projection = {
    ContactsContract.Contacts.LOOKUP_KEY,
    ContactsContract.Contacts._ID
}

uri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI, Uri.encode(data)); //data = email address
cur = resolver.query(uri, projection, null, null, null);

if (cur != null){
    while (cur.moveToNext()){
        msg.set_contact(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)), cur.getLong(cur.getColumnIndex(ContactsContract.Contacts._ID)));
    }
}

以上code工作,因为它发现的电子邮件地址与手机上的联系人相关联。

The above code works in that it finds that the email address is associated with a contact on the phone.

问题:我觉得我得到的原始电子邮件地址条目的_id,不是整体接触的_id。因为当我刷新我的存储接触_id,并将其与从上面的不匹配是什么返回相比,尽管我已经证实,电子邮件与我接触存储相关的。

The problem: I think I am getting the _id of the raw email address entry, not the _id of the overall contact. Because when I refresh my stored contact _id and compare it with what is returned from the above they don't match, even though I have confirmed that the email is associated with my stored contact.

下面是我在找我的存储的联系人:

Here is how I am looking up my stored contact:

String[] projection = {
    ContactsContract.Contacts.LOOKUP_KEY,
    ContactsContract.Contacts._ID
}

Uri uri = ContactsContract.Contacts.getLookupUri(contact_id, contact_lookup);

Cursor cur = resolver.query(cLookupUri, projection, null, null, null);
if(cur != null){
    while (cur.moveToNext()){
        msg.set_contact(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)), cur.getLong(cur.getColumnIndex(ContactsContract.Contacts._ID)));
    }
}

我是什么做错了吗?基本上,我只是想获得与输入电子邮件地址相关联的任何接触的CONTACT_ID ...

What am I doing wrong? Basically I just want to get the contact_id of any contact associated with the incoming email address...

任何帮助很多AP preciated!

Any help is much appreciated!

推荐答案

试试这个:

查询ContactsContract.Contacts.Entity。在MIMETYPE选择=vnd.android.cursor.dir / email_v2,而DATA1 =传入电子邮件地址。

Query ContactsContract.Contacts.Entity. Select on MIMETYPE = "vnd.android.cursor.dir/email_v2", and DATA1 = incoming email address.

这将返回一个包含每个原料接触的E-mail地址输入的地址匹配一个排表,但该行也将包含原始联系人的总联系人ID。从这一点,你可以查询ContactsContract.Contacts找到LOOKUP_KEY。

This will return a table that contains one row for every raw contact whose e-mail address matches the incoming address, but the row will also contain the raw contact's aggregate contact id. From that, you can query ContactsContract.Contacts to find the LOOKUP_KEY.

这篇关于尝试使用电子邮件地址取得联系_ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆