Open list of relative urls absolutely in android TextView? - android

In my application (target 4.0), I have a chunk of HTML (which was pulled and parsed from a webpage) that I am displaying in a TextView. This HTML contains a large number of links (up to 100), most of which are relative, but some are absolute. I want the user to be able to click these relative urls URLs to launch a web browser.
How can I do this without going through the HTML and changing the URLs? Can I tap into a link click event?

You have to set a WebViewClient to your WebView and override shouldOverrideUrlLoading (and perhaps onLoadResource too).

You can match URL (and other patterns) using Linkifyand you can parse your content to use <a> tags like this:
Android Make hyperlinks in textview clickable
In other words, you need the href to contain a fully qualified URL, but you can still display the relative URL to the user.
No client URL works without full qualification, so you need to give the client a context. But this allows you to display relative URL's to the user.

Related

How can I copy all visible text of a webView?

I have a webView that loads a page. How do I copy all visible text on the webView? I don't want the innerHTML. I want the visible text. In other words, I want the same text that can be achieved by "selecting all" and copying.
Use a HTML parser which can give you nodes under your body element and keep aggregating text present inside each node. You could use this https://jsoup.org/
as a parser, it is quite established.

Display HTML document in Activity

I am parsing an RSS feed using SAX to display a list of the title of the latest posts.
When I click the title, it opens the browser, showing that URL.
However I want to display the article, including the HTML styling and images in a new activity.
I can get the article part by parsing the variable 'encoded'
Link.
It is pure HTML. It also contains <img src='...'> tags.
What would be the best way to display this in an activity?
TextView can display HTML, but I don't think it displays images.
Webview can show local HTML, but in this case, it will be dynamic.
Is there any way to display an HTML document in an Activity, including styling and images?
I think you need a webview. There's more info here too.

How can I make clicking on list view goto WebView instead of browser?

I have a ListView with tweets that have urls in them. I want the user to stay in my app when they click on the links. Direct them to a webview to display the url when they click on the url. Can Linkify be used to redirect not the url, but the processing of the url to a Webview?
You can do 2 things. One is to modify Linkify to support launching your own Activity. Or you could write your own regex to match those links and create clickable spans in your text to achieve it.
The second approach is presented here: Android: Launch activity from clickable text

Android Get url of hyperlink clicked from TextView' text

I have a textview whose text is some html including hyperlinks. I have set the textview property android:autoLink="web" so that when user clicks the link, the link open in a browser. Now I want to get url when clicked because URLs I am getting from server, have absolute and relative addresses as well. I want to make it absolute in case url is relative. Any idea?
write an if statement on TextView click function to manipulate relative urls to absolute.

Take an element from a website and put into an android app

Okay noob of the year question.
I have a website, which has several div. and one of those div I would like to put as the front end of an android app.
I.E, I have this div id
I want to put that entire element as the android application. Of course add buttons for it for various items, but right now that is my main obsticle.
I dont want to hard code the page into the android application, becuase of course that element changes.
Thank you in advance.
You could use a WebView to display a Website inside your application. See this article. If you want to display only one div of a website, you could move this div to another page. This should be the easiest method to achieve your goal.
BTW: There are no stupid questions ;-)
One option would be to code your site so that this DIV has a unique ID assigned to it. You could then download all of the HTML from your site into a string in your app, parse out this individual div you want (by finding the unique ID) and save it in a string named, say, html. Next you can place this DIV inside of a webview using webView.loadData(html, mimeType, encoding); where "html" is a string containing the div you extracted. So long as that DIV has content that has absolute paths to resources (images/links), it should load and display your content properly

Categories

Resources