Wifi列表中文乱码

同事拿了块海思平台的板子过来,说是Wifi列表中文显示乱码,让我帮忙分析下原因。然后自己查看了下/data/misc/wifi目录:
这里写图片描述

查看了一下wpa_supplicant.conf文件,如下图,
这里写图片描述

在那个板子上发现这里的中文是正常显示的,
然后跟踪了一下Setting调用到Framework的WifiSsid.java中,发现在进行字符编码的时候,Hisi默认处理为GB2312,修改为UTF-8即可。

具体修改的位置:
framework/base/wifi/java/android/net/wifi/WifiSsid.java

    public String toString() {
        byte[] ssidBytes = octets.toByteArray();
        // Supplicant returns \x00\x00\x00\x00\x00\x00\x00\x00 hex string
        // for a hidden access point. Make sure we maintain the previous
        // behavior of returning empty string for this case.
        if (octets.size() <= 0 || isArrayAllZeroes(ssidBytes)) 
            return "";
        // TODO: Handle conversion to other charsets upon failure
        Charset charset = Charset.forName("GB2312");
        CharsetDecoder decoder = charset.newDecoder()
                .onMalformedInput(CodingErrorAction.REPLACE)
                .onUnmappableCharacter(CodingErrorAction.REPLACE);
        CharBuffer out = CharBuffer.allocate(32);

        CoderResult result = decoder.decode(ByteBuffer.wrap(ssidBytes), out, true);
        out.flip();
        if (result.isError()) {
            return NONE;
        }
        return out.toString();
    }    

这里将GB2312修改为UTF-8即可。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值