【问题标题】:Python - Get Contact from Phone NumberPython - 从电话号码获取联系人
【发布时间】:2015-01-24 10:40:03
【问题描述】:

使用 SL4A 和 Python,有没有一种简单的方法可以从电话号码中获取联系人 ID?

电话号码来自短信的“地址”字段。

我试图避免搜索所有联系人。

我使用m = droid.smsGetMessageById(id, None).result 来获取短信。结果如下:

{u'read': u'1', u'body': u"Hello! Your mobile bill's now ready to view at virginmobile.co.uk/youraccount. We'll collect your Direct Debit of 12.12 on or just after 19th Nov.", u'_id': u'1323', u'date': u'1415372649502', u'address': u'1234567890'}

address 条目中的值是发送 SMS 的电话号码。

我想使用此号码获取联系人 ID,但如果可能,我想避免搜索我的所有联系人。

【问题讨论】:

  • 请添加一些输入和预期输出

标签: android python android-contacts phone-number sl4a


【解决方案1】:

我想通了:

def contactFromPhone(phone):

  uri='content://com.android.contacts/data'
  filter='data4 LIKE ?'
  args=['%'+phone+'%']
  columns=['contact_id']

  contacts=droid.queryContent(uri, columns, filter, args).result

  cs=[]
  if len(contacts)>0:
    for c in contacts:
      cs.append(c['contact_id'])

  return cs

'phone' 是规范化的电话号码

返回一个contact_id列表

【讨论】:

  • 我在哪里可以获得更多相同的文档?
猜你喜欢
  • 2015-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 2016-01-08
  • 2014-05-26
  • 2017-04-13
相关资源
最近更新 更多