gpt4 book ai didi

android,我试图找到什么类型的号码(来自联系人)是(手机,家庭,工作)

转载 作者:太空宇宙 更新时间:2023-11-03 12:00:38 25 4
gpt4 key购买 nike

String tmp = txtPhoneName.getText().toString();
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, "DISPLAY_NAME = '" + tmp + "'", null, null);

if (cursor.moveToFirst()) {
String contactId = Cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + contactId, null, null);

while (phones.moveToNext()) {
String number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
number1 = number;
int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));

switch (type) {
case Phone.TYPE_HOME:
// do something with the Home number here...
break;
case Phone.TYPE_MOBILE:
// do something with the Mobile number here...
break;
case Phone.TYPE_WORK:
// do something with the Work number here...
break;
}
}
phones.close();
}

我的问题是,当它处于切换状态时,它不会检查任何内容。它转到 while(phones.moveToNext()) 哪里是我的错误 Phone.TYPE_HOME 不是 int 并且我的类型无法与之比较......最后一个问题,为什么对于某些联系人它获取手机号码和对于其他人的家(在这两种情况下,联系人都有家庭和手机号码)?我想获得一个以 07 开头的号码,如果没有那种号码可以获取联系人的任何号码,然后如何调用该号码... THX

最佳答案

在这里,我将向您展示如何获取任何联系人的家、手机和工作电话号码,首先,您获取任何 contact_id 的 uri,然后使用以下方法获取所有电话类型号码。

while (phone_crsr.moveToNext()) 
{
int phone_type = phone_crsr.getInt(phone_crsr.getColumnIndex(Phone.TYPE));
switch (phone_type)
{
case Phone.TYPE_HOME:
phone_home =phone_crsr.getString(phone_crsr.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(this, "home"+phone_home, Toast.LENGTH_LONG).show();
break;
case Phone.TYPE_MOBILE:
phone_mob=phone_crsr.getString(phone_crsr.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(this, "mob"+phone_mob, Toast.LENGTH_LONG).show();
break;
case Phone.TYPE_WORK:
phone_work=phone_crsr.getString(phone_crsr.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(this, "work"+phone_work, Toast.LENGTH_LONG).show();
break;
}
}

关于android,我试图找到什么类型的号码(来自联系人)是(手机,家庭,工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9636209/

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