Android onesignal notification text in HTML format - android

Hi I would like to send notifications with title and description. Except that the discription form is in html. there is a way to display it using:
Html.fromHtml () or same else
not like this

I am using Firebase to send notifications and in the app i use WebView like this
WebView .loadDataWithBaseURL("", "write html code here", "text/html", "UTF-8", "");
I hope it solve your problem. let me know if u need more help!

Related

Get data from text box of a website using WebView

In my application, I am showing our own e-commerce website in WebView. In that, I have username and password textboxes. I want to get username of text data while he is entering and want to store it in my file. I do not have any control of website(Login page). It is completely build by third party How can I achieve this ? please help.
Thank you in advance.
You can use JavaScript for load data from the webView.
I use following JS code for load html from the webView
JS_PARSER = "(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();"
webview.getSettings().setJavaScriptEnabled(true);
webView.evaluateJavascript(JS_PARSER, <callback for handle response with html>);
evaluateJavascript docs
And try to load data from the html.
As second way you can make JS function for load text from the textBoxs. And execute the function for each textBox.
JS function for load data from textBox:
function myFunction(){
return document.getElementById("f6").value;
}
Android code for second way:
String LOAD_FUN = function getValue(){ return document.getElementById('%s').value; }();
webView.evaluateJavascript(String.format(LOAD_FUN, "<String with textBoxId>"), <callback for handle textBox value>)

Android - How to set a bookmark in webview content?

I have been trying to set a bookmark in my webview text. But cant find any help regarding this. Please guide me how to do it
String html = "<html><head></head><body>"+text1+"</body></html>";
wv.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
refer this project, in this browser he showed first page with most recent bookmarks and recent history. with help of html files and java.
https://github.com/darvin/zirco-browser

How to clear html page before showing into a webview in Android?

I have the URL of a webpage to be displayed into a webview in my Android app. Before showing this page i want to clear the html code of this page from some tag (such as the header, footer, ecc..) in order to show only few information. How can i do it? I tried to solve the issue working with JSoup but i can't understand how to create and pass the "new page" to the webview. Anybody can help me?
EDIT
I cleaned the html code useless through jsoup libraries. Then, always by mean of these, i get head and body content and finally i showing the "cleared" web page through these lines:
headURL = doc.select("head").outerHtml();
bodyURL = doc.select("body").outerHtml();
webview.loadData( "<html>"+headURL+bodyURL+"</html>" , "text/html", "charset=UTF-8");
webview.setWebViewClient(new DisPlayWebPageActivityClient());
The view shows the new page but do not load css files specified in the head(that has not been touched). Who can say me why?
You can fetch the WebPage you want to display as a string, parse and remove whatever you don't want and then load this string as data in your webview.
Something like:
String webContent = fetchPage(url);
String cleanedWebContent = cleanUp(webContent);
webView.loadData(cleanedWebContent, "text/html", "UTF-8");
Of course, you will need to implement fetchPage and cleanUp as they are not Android methods

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!

How to display an html code(which parsed xml) on android application

I am an android developer. I'm calling web service for one functionality and getting following code as output, when the web service is called.
<string xmlns="http://tempuri.org/">
<Response>
<Response_Code>0</Response_Code>
<Response_Description></Response_Description>
<Description></Description>
</Response>
</string>
In between the Description tag i get html code.
I want to display this on android app.
Can anybody tell me, how i can do this?
Thanks
use the following code as taken from http://developer.android.com/reference/android/webkit/WebView.html
and use a webview to display the data as:
String summary =<WHATEVER IS IN YOUR DESCRIPTION TAG> ;
webview.loadData(summary, "text/html", "utf-8");
You could also use the Html class.
someTextView.setText(Html.fromHtml(descriptionText));

Categories

Resources