2

I have a "SIMPLE" problem which I tried for days to resolve but I didn't. I have an HTML with Javascript file encrypted with AES into my asset folder and what I want to do, is loading it into a webview after having decrypted it. I can't use load URL because loadUrl() needs a filePath and my file is encrypted so i can't give it since I have to decrypt it before

webView.loadUrl("file:///android_asset/encrypted.html"); 

so after I tried with

loadData(htmlJsString, "text/html", "UTF-8");

where htmlJsString is the encrypted.html file as a decrypted string but doing so only HTML code is working while javascript is not working( webView.setJavaScriptEnabled(true); ).

So in few words how can I load an encrypted HTML+JS into my webView from asset folder?

2
  • Please explain in detail what "while javascript is not" means. Is this JavaScript embedded in the HTML file? Also bear in mind that your encryption is likely to be pointless -- if your AES passphrase is hard-coded, it will be trivial to reverse-engineer it. Commented Jun 2, 2017 at 16:42
  • javascript is not working and is embedded, as for the passphrase for AES it's not a problem Commented Jun 2, 2017 at 16:44

1 Answer 1

2

Make sure that this flags are set

WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setSupportZoom(true);
webSettings.setDefaultTextEncodingName("utf-8");
Sign up to request clarification or add additional context in comments.

4 Comments

htmlJsString is not a path it is the encrypted.html file which I read and decrypt , it's the content of the file
I know. Read the method documentation, it should work:
I've updated my answer. Pay attention to webSettings.setDomStorageEnabled(true);. Let me know
huuuu thanks it's workingggg... setDomStorageEnabled(true); Grazie per l'aiuto

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.