从线程ID Android开接触ID [英] Android get contact id from thread id

查看:132
本文介绍了从线程ID Android开接触ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个简单的短信应用程序,我使用code下面装我线程列表时获得线程ID,但我无法弄清楚如何使用线程ID来获得接触ID 。我的根和用root探险我可以在数据库中看到有一个接触表具有以下的列

的thread_id | htcthread_id | CONTACT_ID

所以,因为我有线程ID,我应该能够得到的接触ID,但我也需要确保这个工程上的所有设备。我的应用程序是不是根本的方式。

code获得线程ID

 开放的URI = Uri.parse(内容://彩信,短信/通话简单=真正的);
光标C = context.getContentResolver()查询(URI,NULL,NULL,NULL,日期DESC)。
如果(c.getCount()大于0){
    而(c.moveToNext()){
        //线程ID是c.getString(c.getColumnIndexOrThrow(_ ID))
    }
}
c.close


解决方案

我的解决办法收回所有联系人:

 光标指针= NULL;
    尝试{
        光标= context.getContentResolver()查询(Phone.CONTENT_URI,NULL,NULL,NULL,NULL);
        INT contactIdIdx = cursor.getColumnIndex(Phone._ID);
        INT nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);
        INT phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
        INT photoIdIdx = cursor.getColumnIndex(Phone.PHOTO_ID);
        cursor.moveToFirst();
        做{
            字符串idContact = cursor.getString(contactIdIdx);
            字符串名称= cursor.getString(nameIdx);
            字符串phoneNumber的= cursor.getString(phoneNumberIdx);
            // ...
        }而(cursor.moveToNext());
    }赶上(例外五){
        e.printStackTrace();
    } {最后
        如果(指针!= NULL){
            cursor.close();
        }
    }

您需要这个权限在你的清单:

 <使用许可权的android:NAME =android.permission.READ_CONTACTS/>

我希望我已经帮你!

I'm working on a simple sms app and I'm using the code below to get the thread id when loading my threads list but I can't figure out how to get the contact id using the thread id. I'm root and using root explorer I can see in the database there is a contacts table with the following columns

thread_id | htcthread_id | contact_id

So since I have the thread id I should be able to get the contact id but I also need to make sure this works on all devices. My app is not root by the way

code to get thread id

Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
Cursor c = context.getContentResolver().query(uri, null, null, null, "date desc");
if (c.getCount() > 0) {
    while (c.moveToNext()){
        //thread id is c.getString(c.getColumnIndexOrThrow("_id"))
    }
}
c.close

解决方案

My solution to recover all contacts:

    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
        int contactIdIdx = cursor.getColumnIndex(Phone._ID);
        int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);
        int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
        int photoIdIdx = cursor.getColumnIndex(Phone.PHOTO_ID);
        cursor.moveToFirst();
        do {
            String idContact = cursor.getString(contactIdIdx);
            String name = cursor.getString(nameIdx);
            String phoneNumber = cursor.getString(phoneNumberIdx);
            //...
        } while (cursor.moveToNext());  
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

You need this permission in your manifest :

<uses-permission android:name="android.permission.READ_CONTACTS" />

I hope I have helped you!

这篇关于从线程ID Android开接触ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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