Android Calling JavaScript functions in WebView
I figured out what the issue was : missing quotes in the testEcho() parameter. This is how I got the call to work: myWebView.loadUrl(“javascript:testEcho(‘Hello World!’)”);
I figured out what the issue was : missing quotes in the testEcho() parameter. This is how I got the call to work: myWebView.loadUrl(“javascript:testEcho(‘Hello World!’)”);
I finally got it on my own after some reading. Kind of hard when you know nothing about javascript and when the doc is quite thin on the subject. Here is my solution, hope this will help others : With an HTML page containing 2 buttons at the end like that : <div> <button type=”button” … Read more
Have you tried? mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); Example Link: Webview File Download – Thanks @c49
I found an even elegant and simple solution to clearing cache WebView obj; obj.clearCache(true); http://developer.android.com/reference/android/webkit/WebView.html#clearCache%28boolean%29 I have been trying to figure out the way to clear the cache, but all we could do from the above mentioned methods was remove the local files, but it never clean the RAM. The API clearCache, frees up the … Read more
You can use Google PDF Viewer to read your pdf online: 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(“https://drive.google.com/viewerng/viewer?embedded=true&url=” + pdf);
There’s a working example of this in this project. It boils down to: In your assets/fonts folder, place the desired OTF or TTF font (here MyFont.otf) Create a HTML file that you’ll use for the WebView’s content, inside the assets folder (here inside assets/demo/my_page.html): <html> <head> <style type=”text/css”> @font-face { font-family: MyFont; src: url(“file:///android_asset/fonts/MyFont.otf”) } … Read more
I answer this topic just in case someone read it and is interested on the result. It is possible to view a video element (video html5 tag) within a WebView, but I must say I had to deal with it for few days. These are the steps I had to follow so far: -Find a … Read more
Actually this question has many answers. Here are 2 of them : This first is almost the same as yours, I guess we got it from the same tutorial. public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); final WebView webview = (WebView) findViewById(R.id.browser); webview.getSettings().setJavaScriptEnabled(true); webview.addJavascriptInterface(new MyJavaScriptInterface(this), “HtmlViewer”); webview.setWebViewClient(new WebViewClient() … Read more
This is a full solution for all android versions, I had a hard time with this too. public class MyWb extends Activity { /** Called when the activity is first created. */ WebView web; ProgressBar progressBar; private ValueCallback<Uri> mUploadMessage; private final static int FILECHOOSER_RESULTCODE=1; @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if(requestCode==FILECHOOSER_RESULTCODE) … Read more
As per your expectation, I think you want to enable heavy task in your WebView. For that you need to enable ChromeClient, mWebView.setWebChromeClient(new MyWebViewClient()); And your MyWebViewClient class will be, @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = (WebView) findViewById(R.id.activity_main_webview); // Force links and redirects to open in the WebView instead of in … Read more