收到电子邮件类型和电话号码类型的使用标签的android [英] get email type and phone number type 's label used android
问题描述
我想获取电子邮件类型的类型
和电话号码类型的
标签使用,但在即时通讯获取数据使用这些code标签使用其提供的位置意味着回报整数
的价值,但我想在标签中使用。
如果我错了,在我的code?
成功完全得到电子邮件ID,但类型给 INT
。值1,2。
那么如何获得标签类型?
公共字符串[] getEmailid(长_id){
字符串EMAILID = NULL;
字符串emailType = NULL;
尝试 {
光标光标= getContentResolver()查询(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
新的String [] {Email.DATA,Email.TYPE},
ContactsContract.CommonDataKinds.Email.CONTACT_ID +=+ _id,
//我们需要增加更多的选择手机型号
空值,
空值);
如果(光标!= NULL){
而(cursor.moveToNext()){
//这将让你获得多个电子邮件地址
//如果电子邮件地址被存储在一个阵列
// Log.i(回复邮件TYPA,EMAILID);
EMAILID = cursor.getString(cursor.getColumnIndex(Email.DATA));
emailType = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
// TODO自动生成方法存根
如果(EMAILID!= NULL)
打破;
}
}
}
// .....
常见类型(家庭,工作等)作为整数存储。这样就避免了在保持数据库冗余串并允许本地化。你可以查找本地化的字符串为普通型的INT具有以下API:
<一个href="http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html#getTypeLabel(android.content.res.Resources,%20int,%20java.lang.CharSequence)" rel="nofollow">http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html#getTypeLabel(android.content.res.Resources,%20int,%20java.lang.CharSequence)
请注意,当类型为TYPE_CUSTOM,您需要提供自定义标签。下面是一个例子:
int型的= cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
串customLabel = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.LABEL));
CharSequence的emailType = ContactsContract.CommonDataKinds.Email.getTypeLabel(context.getResources(),类型,customLabel);
I want to fetch the type of email type
and phone number type's
label used but when im fetching the data using these code its giving position of label use means return integer
value but i want the label used.
Where i am wrong in my code?
Success full getting email id but for type giving int
. value as 1,2.
So how to get label for type?
public String [] getEmailid(long _id) {
String emailid = null ;
String emailType = null ;
try {
Cursor cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[]{Email.DATA,Email.TYPE},
ContactsContract.CommonDataKinds.Email.CONTACT_ID +" = "+ _id,
// We need to add more selection for phone type
null,
null);
if(cursor != null) {
while (cursor.moveToNext()) {
// This would allow you get several email addresses
// if the email addresses were stored in an array
// Log.i("RETURN EMAIL TYPA",emailid);
emailid = cursor.getString(cursor.getColumnIndex(Email.DATA));
emailType = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
// TODO Auto-generated method stub
if(emailid != null)
break;
}
}
}
//.....
Common types (home, work, etc.) are stored as ints. This avoids keeping redundant strings in the database and allows for localization. You can look up the localized string for the common type's int with the following API:
Note that when the type is TYPE_CUSTOM, you need to provide the custom label. Here is an example:
int type = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
String customLabel = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.LABEL));
CharSequence emailType = ContactsContract.CommonDataKinds.Email.getTypeLabel(context.getResources(), type, customLabel);
这篇关于收到电子邮件类型和电话号码类型的使用标签的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!