不同手机的不同结果

时间:2016-07-03 18:18:14

标签: android httpconnection lg

我有2部手机: 我从中国买的gg g3 和我从以色列买的gg g3

我构建了一个Android应用程序,根据一个关键搜索从网络获得响应(关键搜索可以使用任何语言:俄语,希伯来语,阿拉伯语,英语等。)

在英语中,两款手机都运行良好。

但是,当我使用非英语语言(以上都没有尝试过中文)时,以色列手机仍然可以运行,但中国手机却没有。

当我在中国手机中调试程序时,我看到当我得到响应时的关键搜索(非英语语言)是问号。但是在Isreal手机中,它的功能很棒,所以我尝试了各种编码,但似乎没什么用。

这里是有问题的代码:

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(); 
            }
        }

问题是:我是否需要更改代码中的内容以便中国手机接受其他语言(不仅仅是英语)?如果是这样的话,如果有人可以指导我的答案那就太棒了。如果没有,那么也许我需要更改手机上的设置?两部手机都有相同的操作系统语言(希伯来语)

谢谢大家。

1 个答案:

答案 0 :(得分:0)

所以utf-8是正确的,我不需要在手机上更改任何本地语言我只需要编码keysearch(URLEncoder.encode(关键字,“UTF-8”))。

这是完整的答案:

<asp:UpdatePanel ID="panel1" runat="server">
     <ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="TransactionID" OnRowDataBound="GridView1_OnRowDataBound" OnRowCommand="GridView1_RowCommand" CellPadding="4" AllowPaging="true" PageIndex="2" OnPageIndexChanging="GridView1_PageIndexChanging" HeaderStyle-BackColor ="CornflowerBlue" BorderWidth="1" BorderColor="Gray" Width="100%" CssClass=" table table-hover" >
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkSelect" runat="server"  />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <img style="cursor:pointer" src ="../Images/Icons/plus2.png" />
                <asp:Panel ID ="pnlDetails" runat="server" Style="display: none">
                    <asp:GridView ID="gvDet" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
                        <Columns>
                            <%--<asp:BoundField ItemStyle-Width="20px" DataField="ID" HeaderText="ID" />--%>
                            <asp:BoundField ItemStyle-Width="200px" DataField="ItemType" HeaderText="Type" />
                            <asp:BoundField ItemStyle-Width="250px" DataField="ItemModel" HeaderText="Model" />
                            <asp:BoundField ItemStyle-Width="140px" DataField="ItemQuantity" HeaderText="Requested Quantity" />
                            <asp:BoundField ItemStyle-Width="80px" DataField="ItemUnit" HeaderText="Unit" />
                            <asp:BoundField ItemStyle-Width="100px" DataField="ItemDate" HeaderText="Date Needed" />
                            <asp:BoundField ItemStyle-Width="200px" DataField="ItemDesc" HeaderText="Description" />
                            <%--<asp:BoundField ItemStyle-Width="80px" DataField="ItemStatus" HeaderText="Status" />--%>
                        </Columns>
                    </asp:GridView>
                </asp:Panel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Transaction Number" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblmosID" runat="server" Text='<%#Bind ("TransactionID") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Width="30px" Font-Size="15px" Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Date" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblDate" runat="server" Text='<%#Bind ("DateFiled") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Width="130px" Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblName" runat="server" Text='<%#Bind ("ReqName") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Company" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblComp" runat="server" Text='<%#Bind ("ReqCompany") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Branch" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblBranch" runat="server" Text='<%#Bind ("ReqBranch") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names ="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Business Unit" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblBU" runat="server" Text='<%#Bind ("ReqBU") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Department" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblDept" runat="server" Text='<%#Bind ("ReqDept") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Section" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblsection" runat="server" Text='<%#Bind ("ReqSection") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Status" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblStatus" runat="server" Text='<%#Bind ("TransStatus") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <%--<asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:LinkButton ID ="lnkEdit" runat="server" Text="View" PostBackUrl='<%# "Details.aspx?Id=" + Eval("TransactionID") %>'></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>--%>
        <asp:ButtonField CommandName="editRecord" ControlStyle-CssClass="btn btn-info" ButtonType="Button" Text="View" HeaderText="View Request" HeaderStyle-ForeColor="White">
        <ControlStyle CssClass ="btn btn-info" />    
        </asp:ButtonField>
    </Columns>
    <HeaderStyle BackColor="CornflowerBlue" />
</asp:GridView>
         </ContentTemplate>
     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="GridView1" />
     </Triggers>
     </asp:UpdatePanel>

谢谢大家的帮助。