不同手机的不同结果

different outcome in different phones

我有 2 个 phone: 我从中国买的lg g3 还有我从以色列买的lg g3

我构建了一个 android 应用程序,它根据关键字搜索(关键字搜索可以是任何 language:russian、希伯来语、阿拉伯语、英语等)从网络获得响应

在英语中,phone两个都很好用。

但是当我使用非英语语言时(以上都是,没试过中文)以色列 phone 仍然很好用但中国 phone 不行。

当我在中国调试程序时phone 当我得到响应时,我看到关键字搜索(非英语语言)是问号。但在 Isreal phone 它工作得很好,所以我尝试了各种编码,但似乎没有任何效果。

这是有问题的代码:

HttpURLConnection connection = null;
        try {
            //Create connection
            URL url = new URL("https://www.example.com/results?search_query="+keyword);
            connection = (HttpURLConnection)url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0");
            connection.setRequestProperty("Accept-Charset", "UTF-8");
            connection.setRequestProperty("content-type", "application/x-www-form-urlencoded; charset=utf-8");
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(connection.getInputStream(),"UTF-8"));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
                response.append('\r');
            }
            m_htmlDoc = response.toString();
        } catch (Exception e) {
            e.printStackTrace();
            m_htmlDoc =  null;
        } finally {
            if(connection != null) {
                connection.disconnect(); 
            }
        }

问题是:我是否需要更改代码中的某些内容以便中国 phone 将接受其他语言(不仅仅是英语)?如果是这样,如果有人可以指导我找到答案,那就太好了。如果没有,也许我需要更改 phone 上的设置?两个 phone 都具有相同的 OS 语言(希伯来语)

谢谢大家

所以 utf-8 是正确的,我不需要更改 phone 上的任何本地语言,我只需要对关键字搜索进行编码(URLEncoder.encode(关键字,"UTF-8")).

这是完整的答案:

HttpURLConnection connection = null;
        try {
            //Create connection
            URL url = new URL("https://www.example.com/results?search_query=" + URLEncoder.encode(keyword, "UTF-8"));
            connection = (HttpURLConnection)url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0");
            connection.setRequestProperty("Accept-Charset", "UTF-8");
            connection.setRequestProperty("content-type", "application/x-www-form-urlencoded; charset=utf-8");
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(connection.getInputStream(),"UTF-8"));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
                response.append('\r');
            }
            m_htmlDoc = response.toString();
        } catch (Exception e) {
            e.printStackTrace();
            m_htmlDoc =  null;
        } finally {
            if(connection != null) {
                connection.disconnect(); 
            }
        }

谢谢大家的帮助。