Android view html source

6. FROM_HTML_SEPARATOR_LINE_BREAK_HEADING: This flag is used to indicate that texts inside ,,,, and elements will be separated from other texts with one newline character by default.

    elements will be separated from other texts with one newline character by default.

9. FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH: This flag is used to indicate that inside

elements will be separated from other texts with one newline character by default.

Example 1 Of Parse HTML File content Using WebView With Example In Android Studio:

Below is the example of HTML in which we parse the HTML file and display the HTML content in our Android WebView. In this example firstly we create a assets folder and store a HTML file in it. After that we create a WebView in our XML file and then get the reference of WebView in our MainActivity and finally with the help of loadUrl() method we display the content in our webView.

Читайте также:  Count in sql and php

HTML in Android Example

Step 1: Create a new project and name it HtmlExample.

Step 2: Open res -> layout -> activity_main.xml (or) main.xml and add following code:

In this step we open an xml file and add the code for displaying a WebView.

Step 3: Now create assets folder in App. You can read here how to create assets folder in Android Studio

Step 4: Now inside assets folder add a HTML file name myfile.html. You can read here how to add local html file in Android Studio. Also inside myfile.html add the below HTML content or add any content in HTML format.

Step 5: Now Open src -> package -> MainActivity.java

In this step we open MainActivity where we add the code to initiate the WebView and then display the HTML content from file stored in assets folder into WebView.

package abhiandroid.com.htmlexample; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.webkit.WebView; public class MainActivity extends AppCompatActivity < WebView webView; public String fileName = "myfile.html"; @Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // init webView webView = (WebView) findViewById(R.id.simpleWebView); // displaying content in WebView from html file that stored in assets folder webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("file:///android_asset/" + fileName); >>

Now run the App and you will see local content added in HTML file is loaded in Webview.

Example 2 Of HTML In Android Studio Using TextView:

Below is the example of HTML in which we display the HTML content in our Android TextView with the help of fromHtml() method. In this example firstly we create a TextView in our XML file and then get the reference of TextView in our MainActivity and finally with the help of fromHtml() method we set the content in our TextView.

HTML in TextView Android Studio

Step 1: Create a new project and name it HtmlExample.

Step 2: Open res -> layout -> activity_main.xml (or) main.xml and add following code:

In this step we open an xml file and add the code for displaying a TextView.

Step 3: Now Open src -> package -> MainActivity.java

In this step we open MainActivity where we add the code to initiate the TextView and then set the HTML content which is stored in a string variable into TextView using fromHtml() method.

    \n» + «
  • One\n» + «
  • Two\n» + «
  • Three\n» + «
    \n» + «
  1. One\n» + «
  2. Two\n» + «
  3. Three\n» + «

Now run the App and you will see HTML content is shown in TextView.

Example 3 Of HTML content in WebView With Example in Android Studio:

Below is the example of HTML in which we display the HTML content in our Android WebView. In this example firstly we create a WebView in our XML file and then get the reference of WebView in our MainActivity and finally with the help of loadDataWithBaseURL() method we display the content in our webView.

HTML WebView Example in Android Studio

Step 1: Create a new project and name it HtmlWebViewExample.

Step 2: Open res -> layout -> activity_main.xml (or) main.xml and add following code:

In this step we open an xml file and add the code for displaying a WebView.

Step 3: Now Open src -> package -> MainActivity.java

In this step we open MainActivity where we add the code to initiate the WebView and then display the HTML content which is stored in a string variable into WebView.

    \n» + «
  • One\n» + «
  • Two\n» + «
  • Three\n» + «
    \n» + «
  1. One\n» + «
  2. Two\n» + «
  3. Three\n» + «

Now run the App and you will see HTML content is displayed using Webview.

Источник

How to view website HTML/CSS source code on Android

view HTML source code android

This is one of those things that has always bothered me, but I never got around to doing and that is being able to view the source code of a website on Android.

For the most part I don’t do any actual coding on my phone, but there are many circumstances where I have to view the source code of a website while on my Android phone.

As an SEO, being able to view HTML source code on the fly is very important for me. I am always analyzing new websites, doing proposals and helping people with issues. As an SEO there are many times when I can’t get to a desktop and need to view the HTML or CSS source code on my Android phone.

View HTML source code on Android Without an app

While there is a way to view the HTML source code of a website on an Android via chrome natively (without a plugin or an app) there really isn’t much flexibility. To do so, all you need to do do is go to Chrome and within the URL / location bar enter:

view-source:http://www.example.com

Once you do that Chrome will display the source code right within the browser:

no app native android view HTML source code howto

So if you are viewing a website and want to view the source code, just replace the “http” with “view-source” and it’ll pop right up for ya.

View HTML source code on Android with an app (my preferred method)

While in general I am not a huge fan of using apps for things a device can do natively, in this case I do prefer using the VT view source app to view HTML or CSS source code on my Android device.

This is the best app that I’ve found so far, and has done me well over the last few months.

The app is called VT View Source. The VT I believe stands for Vagharshak Tozalakyan who is the developer of this app.

I normally keep this app on my secondary home screen, alongside my other apps so I can launch it easily:

1 view HTML source android desktop

This is the first screen that you’ll see when you launch the app. Enter a URL and you are good to go:

2 view website HTML and CSS source code android open URL

Bam: you can view the source code on an Android phone. It does a great job of showing lien numbers, and highlighting HTML syntax. Links are clickable (if you choose) and will take you to the source code of the link you click, not the actual website.

3 view source android source code

There are a number of settings on this app.

4 view source android menu

You can easily highlight code and copy / paste it into another program.

5 view source for websit HTML on android copy selection

One feature that I like is the ability to validate the HTML via w3.org.

6 view source HTML and CSS on website android validate

With one click you can view some cool page info, such as how many lines of code it is and the total number of characters.

7 view CSS HTML source android basic info

Landscape view is also quite nice, and in my opinion the preferred way to view the code.

8 view website source android landscape

You can bookmark websites, and manage your bookmarks.

10 view source android bookmark organization

Another view of the settings. You can change the background color, text color, zooming, font size (%), syntax highlighting and a number of other options.

11 settings view source android

In addition to HTML and CSS, this app can also view source code for other languages such as JavaScript. I did not test any other languages:

Источник

Getting the HTML source from an Android WebView

On and off I’m working on writing an Atom/RSS feed reader for Android. The feed reader is using an Android WebView to display the contents of a feed and to be able to debug some issues I had I wanted to be able to view the HTML source for a page.

That’s should be simple I though, just do WebView.getData() and show it in a dialog. But no, there’s no method to get the HTML source from a WebView, so one has to jump through a lot of hoops to do that. Also the examples I found uses WebView.addJavaScriptInterface to do its job which is not such a good idea because addJavaScriptInterface has security problems and doesn’t even work on Android 2.3. And I do want my application to run on fairly old Android devices (I still use a Motorola Defy at work, I like the form factor and that it’s waterproof).

So after a bit of thinking I figured out an easier way of getting the source. There is a class called WebViewClient which among other things can be used to override what should happen when a follows a link in the WebView. This together with a bit of JavaScript can be used to get the source.

First, when initializing the WebView, tell it to use a custom WebViewClient:

 mWebView = (WebView) mView.findViewById(R.id.web); mWebView.setWebViewClient(new MyWebViewClient()); 

When asked to view the source, enable JavaScript for the WebView and then inject a bit of JavaScript which builds and follows an URL containing the HTML:

The custom WebViewClient will catch this URL:

 public class MyWebViewClient extends WebViewClient < public boolean shouldOverrideUrlLoading(WebView view, String url) < if (url.startsWith("source://")) < try < String html = URLDecoder.decode(url, "UTF-8").substring(9); sourceReceived(html); >catch (UnsupportedEncodingException e) < Log.e("example", "failed to decode source", e); >mWebView.getSettings().setJavaScriptEnabled(false); return true; > // For all other links, let the WebView do it's normal thing return false; > > 

And we can finally show the source in a dialog:

 private void sourceReceived(String html)

As simple as that. And it seems to work on everything from Android 2.3 up to Android 4.4.

Although what we get from the WebView does not quite seem to be the source code it was fed to begin with. It seems that the WebView will fix up the HTML so that it is correct and will also decode any entitydefs. So for example if the WebView was fed “

Hello Wörld

” what we would get back is “

Hello Wörld ”. It’s still useful for what I wanted to do though.

Christer’s Ramblings

Источник

How to View Web Page Source Code in Android

Almost every desktop browser has the “View Page Source” option. But when you browse the Web with an Android device it might be difficult to realize how to read the source code of a page. However there are several easy ways to do so. In this article we will explain how to view HTML source of a page with different browsers.

View Page Source inside Android Browser

View Web Page Source using Android Browser

View Web Page Source using Android Browser

1. Open Android Browser.
2. Enter the URL of a website.
3. Type the following string in the URL address bar:

then tag “Go” button. Remember that JavaScript code is case sensitive!

Source code will be shown in a popup message window in plain text, without formatting.

View Page Source inside Chrome or Firefox Browser

View Web Page Source using Chrome or Firefox Browser

View Web Page Source using Chrome or Firefox Browser

To view the source code of a web page using Chrome or Firefox for Android browsers do as follows:
1. Open Chrome or Firefox browser.
2. Enter the URL of the website.
3. Tap the URL address bar at the top of the browser app.
4. Type at the beginning of the URL:

(e.g. view-source:http://xslab.com/). Then tap “Go” button.

View Page Source inside Opera Mini Browser

View Web Page Source using Opera Mini

View Web Page Source using Opera Mini

1. Open Opera Mini web browser.
2. Enter the URL of the website, wait for the site to load.
3. In the URL address bar type:

VT View Source Application

VT View Source Screenshot

VT View Source is a free application that allows you to view HTML, CSS, JavaScript and XML source codes or remotely located files.

You can open web page with VT View Source by typing the URL address directly in the application, or by using “Share page” functionality within your browser.

VT View Source has an adjustable interface and it comes with multiple syntax highlighting themes. Other application features include line numbering, text wrapping, and User Agent switching.

VT View Source Screenshot

VT View Source Screenshot

Источник

Оцените статью