0

I am writing an app where I want to get the model type of the device and relay it to my server. I am currently doing this in this way:

try{
    String path = URLEncoder.encode(Build.MODEL, "utf-8");
} catch (UnsupportedEncodeingException e) {
    e.printStackTrace();
}

HttpGet httpGet = new HttpGet(baseUrl + "/" + path);

My question is if the Build.MODEL string that is returned will always be UTF-8 encoded?

Does anyone know?

Thanks

1
  • 1
    All strings in Java are UTF-16 encoded in memory. If you request encode() to encode such a string as UTF-8, the output will be UTF-8 encoded, where appropriate byte octets are formatted in %HH syntax. Commented Oct 3, 2014 at 0:23

1 Answer 1

1

Java strings (UTF-16) can be encoded as UTF-8, see this method in String class, it clearly mentions all strings can be encoded as UTF-8.

So in your code above, path String is guaranteed to always come out as UTF-8 encoded.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.