Error entering data with accent

0
I'm sending the data by URL to my webservice if I put the path through the web browser example in Chrome: meuwebservice/inserirusu/João_da_Silva/fotógrafo and calling a method to to display shows like this:

Nome: João da Silva
profi: Fotógrafo

Now when I call the following method it shows me like this:

Nome: Jo?o da Silva
profi: Fot?grafo

I put it to display the path that I'm going through Android and it's the same one that I put for Chrome.

 private void inserir(final String edicao) {  edicao = "João_da_Silva/fotógrafo
    showProgressDialog();

    StringRequest strReq = new StringRequest(Request.Method.GET,
            Const.URL_EDITAR_TRABALHADOR+edicao, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, response.toString());
            if(response.equal("Alterado"){
               hideProgressDialog();
               finish();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            hideProgressDialog();

        }
    });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

}

How can I resolve this?

I was making error to display in logcat and it showed me that this is the android

meuwebservice/inserirusu/Jo?o_da_Silva/fot?grafo

Plus I displayed before submitting and the path is correct on System

    
asked by anonymous 05.11.2014 / 13:13

1 answer

2

You need to encode the url correctly, when you type this in the address bar of the browser it already does this automatically and so it works.

You can use URLEncoder.encode for this, remembering that it should only encode the parts that may have accent or other special characters

String edicao = URLEncoder.encode("João da Silva", "UTF-8") + "/" + URLEncoder.encode("Fotógrafo", "UTF-8");

It should also solve the problem of spaces, which in a URL should be replaced by a + sign and not by underline.

    
06.11.2014 / 12:44