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.
Related
i have a url link am trying to send to my user, but the link breaks up cause. it sends the full link but about half of it is not underlined as a link. this is what am trying to send
String locateUrl="http://maps.google.com?q="+latitude()+","+longitude();
first it does not recognize this ?q= as a link and it just breaks up from there, have checked other answers and tried them but seems not to be working
Just solved this by putting "/" before ?q= thereby making sure the link doesn't break
full link will then be
String locateUrl="http://maps.google.com/?q="+latitude()+","+longitude();
Your link may be breaking because of space at the beginning or in between trim it and then use it.
String locateUrl="http://maps.google.com?q="+latitude()+","+longitude();
locateUrl = locateUrl.trim();
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 :)
I want to print from my android application to the printer I registered with Google cloud print. But every time I tried printing the web page, I always got the document missing error. This is my code but I don't know which line is causing the error.
public void print() {
Uri docUri = Uri.parse("http://myserver.com/view/myusername");
String docMimeType = "text/html";
String docTitle = "myTestPage";
Intent printIntent = new Intent(myContext, PrintDialogActivity.class);
printIntent.setDataAndType(docUri, docMimeType);
printIntent.putExtra("title", docTitle);
startActivity(printIntent);
}
So basically, http://myserver.com/demo/view/myusername is the web page I want to print and text/html is the mime type I provide. Can someone tells me which part of it that causes the error because I tried the URL from my laptop browser and the web page is loaded. Thank you very much. :D
Well, I'm not sure what's wrong with my code, and I still haven't got the slightest idea what should the mime type be. So I came up with a solution:
Generate the html file programatically
Print it with "text/html" type
That should get it done. :)
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!
I have a WebView that I'm using to open some files stored in the assets/ directory of my project. It works fine for most of the files, but there's one in particular (and I'm sure others I haven't found) that it just will not open.
The file I'm having problems with is named:
"assets/ContentRoot/Photos/XXX Software Logo - jpg - 75%.JPG"
When I pass it to WebView, and it shows the error page, it shows it as:
"file:///android_asset/ContentRoot/Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%.JPG"
I then tried running URLEncoder.encode() on it and got the error page with the URL presented as:
"file:///android_asset/ContentRoot/Photos/XXX+Software+Logo+-+jpg+-+75%.JPG"
Neither of these URLs were able to open the file (and they both look okay to me). Anyone have any ideas?
UPDATE: If I encode the % by hand (using %25, as commonsware.com suggested) then it loads the image, but it tries to parse it as text, not as an image, so I just get a lot of (basically) garbage.
Also, referring to the image in an HTML document with a relative URL isn't working (probably because it's not being parsed as an image?):
<img src="../Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%.JPG" />
<img src="../Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%25.JPG" />
Okay, after spending way too long on this, I've figured out what's going on. Basically, if images stored in the assets/ directory contain a space (e.g., " ") in their file name, they won't render as images.
myWebView.loadUrl("file:///android_asset/testimage.jpg");
works fine. However,
myWebView.loadUrl("file:///android_asset/test+image.jpg");
just throws a not found error and
myWebView.loadUrl("file:///android_asset/test image.jpg");
// and
myWebView.loadUrl("file:///android_asset/test%20image.jpg");
show it improperly displayed (as text... see screenshot in question).
This unexpected behaviour is present on (at least) 1.5, 1.6, and 2.0 and I filed a bug report.
Try getting rid of the % in the filename. Or, escape it as %25.
I would guess that WebView only understands text related content types so it faithfully treating your JPG as base64 encoding, decodes and displays resulted gobble-goop as text. I don't really know if it's possible to set content type for WebView but as workaround you can try to throw img tag inside html tag and load resultet page. Also you probably can only use WebView#loadDataWithBaseUrl