HTML SMS message body. Everything after & symbol disappears - android

I'm currently developing a web app and there is this part of the code where I have to pre-populate the message in the sms box. So my code looks like this:
SMS
In the pre-populated message, everything from the & symbol onwards does not appear in the message box on the phone. I know I have to encode it but I do not know what the encoding code is. Any solution to this? Thanks.

This seems really crazy but encoding the body twice does the trick.
not encoded (doesn't work)
uri component encoded (doesn't work)
double uri component encoded (works fine)
Working fiddle to test from an android device: https://jsfiddle.net/k96g2h48/

Android and iOS respond to slightly different syntaxes. To put & inside the body of text, iOS needs URL encoding. For Android, it requires double encoding as mentioned in #Crisman's answer. check the below code:
iOS
<br>
double uri component encoded (works fine)
The first link worked in iOS and the second link works in Android.
Notice the syntax of both URLs. & and ? with this they with & ios distinguish between number and body part whereas ? is used to separate number and body.
An example with number is like
iOS
<br>
double uri component encoded (works fine)
You can also try this fiddle

Encode your & character because it has a special meaning in an URL ( it is the separator for fields)
SMS
The characters that have a special meaning in URL need to be ecnode if you just want there text respresentation.
wikipedia on percent encoding

Try using & instead of "&" as this is the ASCII version of the character and used to show up as text in a HTML document

I think you need to write like below
SMS

Have you try this char \u0026?
SMS
reference from - https://stackoverflow.com/a/3705601/10989990
EDIT
Some browsers will accept & and some browsers will not accept this char so everything after & will be considered as the query parameter
EDIT
may be javascript helps to use
<!DOCTYPE html>
<html>
<body>
<script>
var txt = "SMS";
document.write("<p>" + txt.link("sms:?body=This is the message with & symbol") + "</p>");
</script>
</body>
</html>
Good Luck :)

Related

replace + with space in html Gmail/Android chrome

Hi i have web application which uses mailto like
Send email
but no meter what i do it alway replace space with + sign
Try to decode your String
just use Uri.encode(String).
subject = (EditText) findViewById(R.id.subject);
subject.setText(Uri.encode(WhatEverYourStringVarIs));
This will help you to decode the URIencode.
If you mean the PHP (HTML) Issue just do the same:
$encodeString = urlencode($encodeString);
echo $encodedString;
So the String will displayed proper.
See this url encode.
Okay, but when i'm read your Question the third time: You can use Spaces in these HTML case. It is an Android Bug. Just use this:
Send Mail

Work with the link with special character (e.g. traditional chinese , empty space) in android

I am working with special character in URL for android
However, I encounter two problem
1) empty space
If I have a query inside url
e.g. test.php?test=aaa bbbb cccc
Then the query will not include bbbb and cccc, I learnt that I should replace the " " to %20, however, instead of using replace(" ","%20"), how can I do it in more standard way?
2) traditional chinese in url
I have an image url like this:
http://oshc.zizsoft.com/wp-content/uploads/2014/04/1-職安健資訊產品目錄2013-220x300.png
If I directly pass to android, it fail. but if I copy the link to my desktop browser , it change to like this, then I paste it on android, it works
"http://oshc.zizsoft.com/wp-content/uploads/2014/04/1-%E8%81%B7%E5%AE%89%E5%81%A5%E8%B3%87%E8%A8%8A%E7%94%A2%E5%93%81%E7%9B%AE%E9%8C%842013-220x300.png";
What should I do to encode to this?
Thanks for helping
Update:
it change to
http%3A%2F%2Foshc.zizsoft.com%2Fwp-content%2Fuploads%2F2013%2F12%2FSQ1-351x300.jpg
How can I fix that? Thanks
1) Try trimming the url, it wil remove the spaces from url. I guess its bit more staanddard way to solve this issue.
2) This problem is eactly due to the encoding issues. Our Android default encoding is cp1252...and those strings will not be encoded in the same way so when it used in the code its automatically changes to some other symbols. So try changing the encoding of the project and string to the same like UTF-8 or something. You can change project encoding by
Properties> Resources> Encoding
Hope my suggesions will help you a bit.
Try this links also
1. Trimming
2. Encoding
If you want to programmatically encode and decode URLs then use URLEncoder and URLDecoder class available in Java as well as Android.
// To encode URL
URLEncoder.encode(url, charset);
// to decode url
URLDecoder.decode(url, charset);

Android - Characters such as å,ä,ö do not render correctly in WebView

I am using the following code to render my webview in android -
webview.loadDataWithBaseURL(null, "Subject: "+ getSubject() +" Content: "+ getContent() , "text/html" , "UTF-8", "");
The subject and content that I receive from the server are UTF encoded and show wrongly as Ã¥,ä,ö in the log and on screen. However in iOS webview they show up correctly as å,ä,ö. How do I get them to show as å,ä,ö in android as well?
make sure the content you recieve, in tag <head> use like this: <meta charset="UTF-8" >
Sorry for my English. :)
I think it's more of a font problem than code itself. Try putting DejaVuSans.ttf font instead of DroidSansFallback.ttf on the android itself. It should fix it. I'd search forum.xda-developers.com for a solution.
It was due to how I was retrieving the message from the server. I was reading the Http response character by character so it broke up the encoding. When I started reading line by line it worked fine!

Encoding URL with German Characters

In my app I receive a URL such as
http://www.wassersportlotse.de/php/lib/smart_image_resizer/image.php/Mühlendammschleuse.jpg?image=/media/images/uploads/Mühlendammschleuse.jpg
When there are no German characters in the fullurl I can just use it without encoding and it works fine. However if I receive a URL such as the one above it doesn't work (the ü is causing the problem). Below I have tried to encode the seperate parts of the URI to no avail. As alway advice is very much appreciated.
public ImageDownloader(String fullurl) throws URISyntaxException{
URI uri = new URI(fullurl);
path = uri.getPath();
path = URLEncoder.encode(path);
query = uri.getQuery();
query = URLEncoder.encode(query);
auth = uri.getAuthority();
url = "http://" + auth + path + query;
}
Maybe the encoder das encode the Umlaut as UTF-8 characters (so ü would be encoded with two characters) and they are not put back together properly at the server (for us it didn't work with Tomcat). To solve this situation we used URLEncoder.encode(param, "ISO-8859-1") to encode the parameters.
There's no simple answer, because it depends on the server serving that URI which encoding is expected.
Usually it's UTF-8.
In that case: use String.getBytes, specifying the UTF-8 encoding, and obtain a byte array from that. Re-encode that byte array as string by taking all bytes <= 127 as-is, and substituting all others by the %hh form. (percent sign, then two hex digits). See http://greenbytes.de/tech/webdav/rfc3986.html#rfc.section.2.1.
You can use Android's Uri class to help you out. That class has an encode() method which will use UTF-8 to encode your string.
I recently had a problem with URLs for images whose names included umlauts and German special characters, and I lost a day looking for the solution. The images simply did not appear if there was an ä or and ü in the file name or the directory name. I thought it might be spring, or some other Java technology I am working with, or in the browser. And strangely enough, even with the url encoded, it failed to find the image. But in the end, the solution was in my tomcat server.xml configuration. In your server.xml file, find your connector and add these two lines:
URIEncoding="UTF-8"
useBodyEncodingForURI="true"
At the end, it should look something like this:
<Connector connectionTimeout="20000"
port="8080"
protocol="HTTP/1.1"
redirectPort="8443"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"/>
Now I do not need to url-encode the url. This is a help to my clients, because they can see the German words in the urls spelled correctly.
Here is another tip: if you are coding in eclipse and starting and stopping your server from inside eclipse, then the configuration file (server.xml) could be in your eclipse workspace in the Servers folder. It must be changed here for it to work with eclipse. This can be maddening, when you have made the change in your principal tomcat configuration, and the urls work there, but they are still broken when running the server in eclipse.
That did it for me. I hope it helps someone out there! :-)
Have your tried unsing:
android.net.Uri.encode(urlString, ":/");
It encodes the string but skips ":" and "/".

How to get line breaks in message supplied for Android Sharing

Android Sharing Intent takes a string for the body.
How do you introduce a line break? Gmail appears to do plain text by default, and so I can't get any line breaks in my sharing message.
\n, , <br />, and 0x0A all don't work.
Okay \n does indeed work. And if you change the sharing intent setType to text\html, then < br />.
My problem was caused by issues inside HTML templating and then sent through a phonegap sharing plugin.

Categories

Resources