Skip to content Skip to sidebar Skip to footer

Url Encoding Is Getting Failed For Special Character. #android

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 o

Solution 1:

One solution would be to define your allowed character scope. Then either replace or remove the characters that fall outside of this scope.

Given the following regex:

[a-zA-Z0-9 -+&#]

You could then either do:

input.replaceAll("[a-zA-Z0-9 -+&#]", "_");

...or if you don't care about possibly empty results:

input.replaceAll("[a-zA-Z0-9 -+&#]", "");

The first approach would give you a length-consistent representation of the original Bluetooth device name.

Either way, this approach has worked wonders for me and my colleagues. Hope this could be of any help 😊.

Post a Comment for "Url Encoding Is Getting Failed For Special Character. #android"