机器人 - 获取昵称的昵称和类型 [英] Android - Get Nickname and Type of Nickname
问题描述
我一直试图让几个小时的接触的绰号,现在,还是不能让他们的工作,我已经被告知,他们是位于不同表中的电话号码等。但我不知道如何使用它们。
I've been trying to get the nickname of a contact for a few hours now, and still cant get them to work, I've been told that they are in a differnt table to the phone numbers etc.. But i dont know how to access them.
我得最近的就是这个。
Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts._ID +" = ?", new String[]{String.valueOf(recordId)}, null);
while (cursor.moveToNext()) {
Cursor nickname = context.getContentResolver().query( ContactsContract.Data.CONTENT_URI, null, ContactsContract.CommonDataKinds.Nickname.CONTACT_ID +" = "+ recordId, null, null);
while (nickname.moveToNext()) {
try {
String nicknameName = nickname.getString(nickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
String nicknameType = nickname.getString(nickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.TYPE));
switch (Integer.valueOf(nicknameType)) {
case 1: nicknameType = "TYPE_HOME"; break;
}
list.add(new KeyValue("Nickname:" + nicknameType, nicknameName));
} catch (Exception e) { continue; }
}
nickname.close();
}
这得到接触的所有数据以及类型,例如:托马斯Owers
1
这是所有好但它并没有给我的数据是什么,所以它提供了电子邮件,电话,姓名,昵称,但我不能区分它们。
This gets all the data of the contact along with the type eg: Thomas Owers
1
this is all good but it doesn't give me what the data is, so it gives the email, phone, names, nickname but i cant distinguish between them.
任何帮助将是多大的preciated,谢谢! :)
Any help would be much apreciated, Thank you! :)
推荐答案
我能够好几个小时在网上搜索后得到的绰号......
I was able to get the nickname after several hours of searching the internet...
ArrayList<KeyValue> list = new ArrayList<KeyValue>();
Cursor cursor = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts._ID +" = ?", new String[]{String.valueOf(recordId)}, null);
while (cursor.moveToNext()) {
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] params = new String[] {String.valueOf(recordId), ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE};
Cursor nickname = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, where, params, null);
while (nickname.moveToNext()) {
String nicknameName = nickname.getString(nickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
String nicknameType = nickname.getString(nickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.TYPE));
switch (Integer.valueOf(nicknameType)) {
case 1: nicknameType = "Default"; break;
case 2: nicknameType = "OtherName"; break;
case 3: nicknameType = "MaidenName"; break;
case 4: nicknameType = "ShortName"; break;
case 5: nicknameType = "Initials"; break;
}
list.add(new KeyValue("Nickname:" + nicknameType, nicknameName));
}
nickname.close();
}
return list;
这code得到的外号! :)
This code gets the nickname! :)
这篇关于机器人 - 获取昵称的昵称和类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!