I have an application where I m using an sms provider to send sms to my android device. I am sending a message of the following form:
message = "value: "+Float.toString(float1)+" and ratio: "+Float.toString(float2)
I m using the jva.net library and the code is :
System.out.println("Sending sms");
InputStream response = null;
URLConnection connection = null;
try {
connection = new URL("https://somesmsprovider.com/sms/sms.jsp?user=user&password=pass&mobiles=xxxxxxxxxx&sms="+message).openConnection();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
However, what i receive on my device is just: "value:"
I guess it has to do with the encoding. The provider has an option to activate unicode encoding but that didnt help either. Anybody has an idea why I m not able to display the sms properly?
Thnks
Apparently the spaces in the resulting URL were causing the problem. Simply replacing them with their percent-encoded value - %20
- seems to do the trick.
message = message.replace(" ", "%20");
If you include any characters in your message other than the alphanumerics and basic punctuation, you may need to URL-encode the whole String
. The URLEncoder
class is available in Android, though it encodes spaces as +
, so you might have to perform a replace()
similar to the above after the encoding, as I would imagine +
would go through unchanged in the message body.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments