gpt4 book ai didi

android - 通过 thread_id 取得联系

转载 作者:行者123 更新时间:2023-11-29 00:10:50 24 4
gpt4 key购买 nike

我在讨论这个话题Android get contact id from thread id有人和我问的问题完全一样。不幸的是,lopez.mikhael 的回答完全没有中标。

如何从 URI content://sms/conversations 中获取带有 thread_id 的联系人 ID?假设它返回:

- thread_id
- snippet
- msg_count

获得所有联系方式无济于事。我从那里搜索了 getColumnsNames(),但没有看到任何包含 thread_id 的好列名。

为什么这没有记录在案?是否已弃用 content://sms/ ?还有其他解决方案吗?

谢谢。

最佳答案

如此处所述post

您可以获取短信收件箱:

    Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
String where = "thread_id="+ <thread id you get it from content://sms/conversations>;
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, where, null, null);
String[] columns = new String[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
while (cursor1.moveToNext()){
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
}
}

您可以通过更改 URI 来获取其他已发送的项目。

Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");

如果你有电话号码,你可以使用下面的代码找到联系方式

String contactid = null;

ContentResolver contentResolver = getContentResolver();

Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phonenumintolist));

Cursor cursor = contentResolver.query(
uri,
new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID},
null,
null,
null);

if(cursor!=null) {
while(cursor.moveToNext()){
String contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
contactid = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
}
cursor.close();
}
if (contactid == null) {
Toast.makeText(DetailedCallHistory.this, "No contact found associated with this number", Toast.LENGTH_SHORT).show();
}else{
//You can contact id do what you want to do with it.
}

关于android - 通过 thread_id 取得联系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30238447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com