获取电子邮件类型和电话号码类型的标签使用android

我想获取电子邮件类型和电话号码类型的标签类型,但是当使用这些代码获取数据时,它的给定位置的标签使用意味着返回整数值,但我想要使用的标签.

我的代码在哪里错了?

成功完全获取电子邮件标识,但类型为int.价值为1,2.

那么如何获取类型的标签

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;
            }
        }
    }
//.....

解决方法

常用类型(家庭,工作等)以int形式存储.这样可避免在数据库中保留冗余字符串并允许本地化.您可以使用以下API查找常用类型的int的本地化字符串:

http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html#getTypeLabel(android.content.res.Resources,%20java.lang.CharSequence)

请注意,当类型为TYPE_CUSTOM时,需要提供自定义标签.这是一个例子:

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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...