Java Android WebView Displaying a string - java

i have an application that fetch html from a websites, exactly in a webpage permitted only tu logged in user, so i have setted the login cookie and i get back the html webpage to a string, i tryied to easily take this string off from emulator, but i can't do copy-paste trought emulator-pc, does someone know how can i load a webview to reder my string and make me seeing if i am logged in and all work or not?
If it's possible i'd like to directly render the string, without saving it to an html file and opening it... is this possible?
Thanks, matteo.

Setting webview content form String:
public static void loadHtmlToWebView(WebView view, String html) {
view.loadData(Base64.encodeToString(html.getBytes(), Base64.DEFAULT) , "text/html", "base64");
}

Related

Gather text-data from html file

I'm making an app which will display quite a lot of information in text. I would love to be able to change this text without having to do any updates to the app itself and there-fore it would be great to just get the text from a simple HTMl-file from a server and display it in a textview. Is this possible?
TL;DR: Is there a way to display text from a remote HTML-file in a textview?
-Alexander
Your app can send a request to get your HTML page and then set the value of a TextView to be the content of the page as shown in this example: https://developer.android.com/training/volley/simple.html

Call HTML page with javascript content

I am stuck at an issue, I don't know if its possible or not.
I need to call a HTML page, but the page has some content being loaded via Javascript too and I need to get that also.
Is this some how possible ?
Currently I have used plain: new URL(url).openConnection() and it's not returning that.
Any Help ?
Thanks
To do that you'll need to host a WebView in your application. It can be hidden if you want. Call the webview loadUrl to load the content you want. Handle the WebViewClient onPageFinished so you know all of the content has loaded, and then use the javascript bridge interface (addJavascriptInterface) to pass the HTML back up to the application.

Get the main content from RSS Feeds

I've created an application which lists all the feed items in ListFragment. My question is how to load the full text from the link. I've tried with WebView, but it is loading the complete URL. Since RSS XML structure does not have any tags related to full/actual content, can anyone give some reference so that I can use it?
This is how I've tried to load the URL in WebView:
URL = getIntent().getStringExtra("url");
webView = (WebView) findViewById(R.id.activity_display_news_webview);
webView.loadUrl(URL);
You can use boilerpipe to extract the full text from the url

How to retrieve domain name from a webview?

I want to be able to retrieve the domain name in a webview in which the user is able to enter in the URL. I want to post the domain name instead of the URL if this is possible. Any help is greatly appreciated.
You could call getTitle() and getUrl() on the WebView to get the current title and URL, if that's what you're looking for.
You can create a WebViewClient for the WebView and override its onLoadResource method. This will tell you whenever a new web page is being loaded in the WebView, so you can parse that to get the domain and do whatever you need to do with it.

WebView not Loading Data?

I'm trying to load the parsed html data from an rss feed using a
WebView, but the webview claims that the page:
"data:text/html;utf-8,[The html I'm trying to display]"
is not available.
I find it strange that it seems to be putting the html data into the
url, when I just want it to display it.
Here's my code right now for the webview:
Bundle data = getIntent().getExtras();
WebView webview = new WebView(this);
setContentView(webview);
webview.loadData(data.getString("DEFAULTTEXT"), "text/html", "utf-8");
Where the HTML has been passed in a string in the Bundle with the
identifier: DEFAULTTEXT. I've tested the class and the HTML is passed
fine, it just isn't displayed correctly.
It works fine on some of the webpages I've tried, but not others. I'll try to post the code of one that works and one that doesn't.
Huuu.... so I turned my computer on this morning and it worked perfectly. I still don't know what the problem was. :/
Edit: Never mind. It works on some, but not all of the pages I try to display.
Edit2: swapping it out for loadDataWithBaseURL worked like a charm.
As stated, when you have characters like '%', '\', '#' in your HTML, it needs to be escaped which loadData doesn't seem to do automatically.
loadDataWithBaseURL instead of loadData does escape and seems to fix this. Just use null for baseUrl and historyUrl. So the example code in the question is changed to:
Bundle data = getIntent().getExtras();
WebView webview = new WebView(this);
setContentView(webview);
webview.loadDataWithBaseURL(null,data.getString("DEFAULTTEXT"), "text/html", "utf-8",null);
I believe this sporadic behavior of loadData* is because of what is the content of the page you are trying to load. If it is plain simple html it has no problem. But if it has components like css or other features requiring external info, it will bail out.
My experience!
Are you sure you have the correct permissions defined in the manifest.xml?

Categories