URL encoding is getting failed for special character. #Android

ぐ巨炮叔叔 提交于 2020-01-24 11:44:11

问题


I'm working on a solution where need to encode string into utf-8 format, this string nothing but device name that I'm reading using BluetoothAdapter.getDefaultAdapter().name.

For one of sampple I got a string like ABC-& and encoding this returned ABC-%EF%BC%86 instead of ABC-%26. It was weird until further debugging which helped to identify that there is difference between & and &. Second one is some other character which is failing to encoded as expected.

& and & both are different.

For encoding tried both URLEncoder.encode(input, "utf-8") and Uri.encode(input, "utf-8") but nothing worked.

This is just an example, there might be other character which may look like same as actual character but failed to encode. Now question are:

  1. Why this difference, after all it is reading of some data from device using standard SDK API.
  2. How can fix this be fixed. Find and replace with actual character could be a approach but scope is limited, there might be other unknown character.

Any suggestion around !!

来源:https://stackoverflow.com/questions/58486114/url-encoding-is-getting-failed-for-special-character-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!