Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use polymer/web components in a native android app w/o Cordova?

If I'm not mistaken, you need a web server to use/test Polymer's web components (such as the paper elements) on your computer due to browser permissions issues stemming from loading local file://s.

(A simple solution is to navigate to the directory where the polymer files are you want to try and type python -m SimpleHTTPServer then load http://localhost:8000 and all is good.)

But how about if I want to employ web components/Polymer elements in a native java android app inside a simple WebView w/o dealing with Cordova or setting up a web server somehow inside my app. Will I be able to do it easily, or will I have the same permissions issues?

Thanks in advance.

like image 617
fattire Avatar asked Jul 12 '14 00:07

fattire


1 Answers

Yes! I'm hoping to write an article on this in the next few weeks. For the imports to load from file://, I've been successful with the following settings:

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true); // Enable Javascript.
webSettings.setAllowFileAccessFromFileURLs(true); // Enable HTML Imports to access file://.

Note: this is also using the Chrome webview (Android 4.4.3+).

like image 178
ebidel Avatar answered Nov 10 '22 21:11

ebidel