Android的短信内容(内容://短信/发)短信内容、短信、内容、Android

2023-09-05 05:39:24 作者:从我的世界滚犊子

我有一个问题读取从设备的SMS消息中。 在获得内容提供商的URI内容://短信/收件箱, 一切都很好,我可以读人一栏找到外键 到百姓餐桌,并最终达成了接触,他们 名字。

I'm having a problem reading the SMS messages from the device. When acquiring a content provider for the URI 'content://sms/inbox', everything is fine, I can read the "person" column to find the foreign key into the people table and ultimately reach the contact and their name.

不过,我也想遍历发送的消息了。当阅读 从内容://短信/发送,对方场总是显得0的 这个正确的领域是阅读,以找到收件人数据 发送的消息?如果是这样的 - 任何想法,为什么我的始终是0

However, I also want to traverse the sent messages too. When reading from 'content://sms/sent', the person field always appears to be 0. Is this the correct field to be reading to locate the recipient data for the sent message? If so - any idea why mine is always 0?

我所有的测试已经在模拟器中进行,我创建了3 联系人。我在发信息给这些联系人从模拟器 以正常方式你发送邮件。

All my testing has been done in the emulator and I've created 3 contacts. I've sent messages to those contacts from the emulator in the normal manner you'd send a message.

只是重申,我可以看到4发送的消息并阅读 相关正文。我的问题是,我似乎无法读取 人的ID,所以我不能工作了谁收件人。

Just to reiterate, I can see the 4 sent messages and read the associated body text. My problem is that I can't seem to read the "person" ID and hence I can't work out who the recipient is.

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

非常感谢,

马丁。

推荐答案

使用地址栏。我猜的人列被忽略,因为人们可以发送短信到不在联系人列表中的电话号码。

Use the address column. I guess the person column is ignored because people can send SMSs to phone numbers that are not in the contacts list.

// address contains the phone number
Uri phoneUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, address);
if (phoneUri != null) {
  Cursor phoneCursor = getContentResolver().query(phoneUri, new String[] {Phones._ID, Contacts.Phones.PERSON_ID}, null, null, null);
  if (phoneCursor.moveToFirst()) {
    long person = phonesCursor.getLong(1); // this is the person ID you need
  }
}