Android studio: How to artificially display a webpage? - android

I want to show the html file stored in localstorage when I access a webpage using chrome without being connected to the internet.
For example, if you try to access https://google.com without being connected to the Internet
<p>google.com</p>
I want the above html code to be displayed.
How can I perform the above tasks using android studio?
*(My native language is not English. Please forgive me if the sentence is awkward)

Use this code inside activity
WebView wv;
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/aboutcertified.html");

Related

Opening a tab with a PDF attachment in a Webview

We are trying to allow our users to download / display PDF files in a web application (WebView)
The HTML is a simple
<iframe src="path/to/pdf" />
In a standard android browser everything works - when clicking the link, the browser is allowing either display the PDF, or download... (content-type is application/pdf)
When using the webview we do not get the same results - a blank page is showing, (maybe a new tab is not opening correctly?!)
Note - We cannot use Google Viewer - the PDF is in a user restricted area (a session is required) - and so we cannot provide a public link to the PDF, which is required for google viewer to work.
How can we make the webview work just like the regular browser?
HTML is simple but it contains many css, javascript/jquery code dependencies. Which browser renders accordingly and javascript can run on browsers. As browsers are preconfigured to run javascript and render html css.
Android webview is not preconfigured to run javascript, css. It can render html only. So it looks weird in webview as it renders without css and does not run javascript
How to configure webview to run css and javascript, allow go forward in webview and go backword like browser?
Here are full properties listed. Android developers
Then your webview can let users download the file present there..
WebView mWebView = findViewById(R.id.myWebView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new MyWebChromeClient((Activity)mContext));
mWebView.addJavascriptInterface(new testClass(), "jsinterface");
mWebView.loadUrl("UrlToLoad");
You need to append http://docs.google.com/gview?embedded=true&url= to open PDF file in Webview
String docInitialUrl = "http://docs.google.com/gview?embedded=true&url="+docUrl;
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.setInitialScale(100);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(docInitialUrl);

Android application with AngularJS in webview

How can I use AngularJS & H5 for building an Android native/hybrid app without using PhoneGap or Cordova, just simple webview inside android layout file.
Please provide some reference :)
Any AngularJS web app runs fine in a WebView.
To run the website in a WebView all you need to do is this.
final WebView containerWbVw = findViewById(R.id.fragment_wbVw_container_id);
WebSettings webSettings = containerWbVw.getSettings();
webSettings.setJavaScriptEnabled(true);
containerWbVw.setWebChromeClient(new WebChromeClient());
and then load the URL in the WebView using
containerWbVw.loadUrl(WEBAPP_URL);
The WEBAPP_URL can be an HTML page in your assets folder or hosted on your server
//assets folder file
WEBAPP_URL = "file:///android_asset/main.html";
//server link
WEBAPP_URL="https://mysite.mycompany.com/myapp";
In addition to this, you would need to interact with the native android app to send and receive data. For example, a use case would be to get a scanned barcode using the device's camera. For this, you would need a Javasrcript Bridge.

Android HTML WebView

I am creating an application and I am trying to load a HTML page in a web view.
I am using the code
WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/index.html");
but continue to receive an error that the web page at file:///android_asset/index.html might be temporarily down or it may have moved permanently to a new web address.
Any help would be great
from assets folder
webview.loadUrl("file:///android_asset/file.html");
from specific folder
webview.loadUrl("file:///data/data/com.example.example/files/file.html");

Hosting HTML page locally in Android Device

I am developing an android app. In that I have used webview to open the html page.
But some of the features on my HTML page would work only if I access the page through server.
How can I host the HTML page locally on my Android device?
For better Idea:
Example: On PC, I have hosted the html page locally using Apache Tomcat Server.
So to load this HTML page, I have two options
1. Directly double clicking the HTML and opening in browser.
2. Using URL: http://localhost:8080/MyWebApp
The first option is basic and some of features are not supported.
In second approach, all the features work as expected.
Is there any app/sdk/ open source which I can use to locally host the HTML page?``
try this code
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
//webView.loadUrl("file:///android_asset/folderName/index.html");
webView.loadUrl("http://10.0.2.2:8080/MyWebApp");
Put your file to assets folder and write this
webView.loadUrl("file:///android_asset/help.html");

How can i view pdf in android without pdf Application in device?

i want to view pdf file from internet..can anyone tell me how can i view??
Please Use This code For view Online PDF without Using PDF of Application
mWebView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://your_link/634128127095123576.pdf");
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
Please view this answer for more details: how to develop a pdf reader in android
But please be aware that webview does create some extra threads like Cookie Manager and history manager , it might just increase your memory foot print a bit. I saw this behaviour when i looked at threads created in Eclipse ADT plugin

Categories

Resources