androidarabiccalllogno-data

when I switch language to Arabic, the call log page does not display data


In my android project, when I switch language to Arabic, the call log page does not display data, but when I switch to other languages(such as english) can be displayed properly, how to solve, please see the following information.

1.A part of the code for the callLog adapter is as follows:

 //显示归属地
        if (callLog.getBelong_area() != null && !callLog.getBelong_area().equals("")) {
            LogE.e("item","有归属地:"+callLog.getBelong_area());
            holder.belong_area.setVisibility(View.VISIBLE);
            holder.belong_area.setText(callLog.getBelong_area());
        } else {
            LogE.e("item","没有有归属地");
            holder.belong_area.setText("");
            holder.belong_area.setVisibility(View.GONE);
        }

2.It still does not display data when I enter a fixed value,such as follow:

holder.belong_area.setText("北京"); 

3.Print the log log as follows:

08-23 10:07:13.241 17494-17494/com.allinone.callerid E/item: 有归属地:北京 08-23 10:07:13.607 17494-17494/com.allinone.callerid E/item: 有归属地:Shijiazhuang, Hebei 08-23 10:07:13.674 17494-17494/com.allinone.callerid E/item: 有归属地:北京 08-23 10:07:13.714 17494-17494/com.allinone.callerid E/item: 有归属地:湖北省,武汉市

4.Runtime screenshot:

arabic language(wrong),

enter image description here

english language(right)

enter image description here


Solution

  • You should have proper character set of your system.

    You can check the folowing code to detect a charaterset of the language.

    public class CharsetDetectTest {
    
        public static void main(String[] args) {
            detectCharset("北京");
        }
    
        public static void detectCharset(String originalStr) {
    
            String[] charSet 
              = { "utf-8", "big5", "EUC-CN", "iso-8859-1", "gb2312" };
    
            for (int i = 0; i < charSet.length; i++) {
                for (int j = 0; j < charSet.length; j++) {
                    try {
                        LogE.e("charaters",
                            "[" + charSet[i] + "==>" + charSet[j] + "] = "
                            + new String(originalStr.getBytes(charSet[i]), charSet[j]));
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            }
    
        }
    }
    

    The debug output will be

    [utf-8==>utf-8] = 北京
    [utf-8==>big5] = ��鈭�
    [utf-8==>EUC-CN] = ��浜�
    [utf-8==>iso-8859-1] = å京
    [utf-8==>gb2312] = ��浜�
    [big5==>utf-8] = �_��
    [big5==>big5] = 北京
    [big5==>EUC-CN] = �_ㄊ
    [big5==>iso-8859-1] = ¥_¨Ê
    [big5==>gb2312] = �_ㄊ
    [EUC-CN==>utf-8] = ����
    [EUC-CN==>big5] = 控儔
    [EUC-CN==>EUC-CN] = 北京
    [EUC-CN==>iso-8859-1] = ±±¾©
    [EUC-CN==>gb2312] = 北京
    [iso-8859-1==>utf-8] = ??
    [iso-8859-1==>big5] = ??
    [iso-8859-1==>EUC-CN] = ??
    [iso-8859-1==>iso-8859-1] = ??
    [iso-8859-1==>gb2312] = ??
    [gb2312==>utf-8] = ����
    [gb2312==>big5] = 控儔
    [gb2312==>EUC-CN] = 北京
    [gb2312==>iso-8859-1] = ±±¾©
    [gb2312==>gb2312] = 北京
    

    Then, use one of the right characterset.

    holder.belong_area.setText(new String("北京".getBytes("utf-8"), "utf-8")); 
    

    or

    holder.belong_area.setText(new String("北京".getBytes("utf-8")); 
    

    You can check the chinese charater site.

    best regards,