Last active
January 4, 2017 23:19
-
-
Save piotrmadry/ce851c37a87411f493463cf7c41a74df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void loadWebPage(final String pageUrl) { | |
webView.getSettings().setJavaScriptEnabled(true); | |
webView.setWebChromeClient(new WebChromeClient()); | |
webView.setWebViewClient(new WebViewClient() { | |
@Override | |
public void onPageFinished(final WebView view, final String url) { | |
injectJS(view); | |
} | |
}); | |
webView.loadUrl(pageUrl); | |
} | |
private void injectJS(final WebView view) { | |
String jsContent = ""; | |
try { | |
final InputStream inputStream = getAssets().open("script.js"); | |
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); | |
final BufferedReader buffer = new BufferedReader(inputStreamReader); | |
String line; | |
while ((line = buffer.readLine()) != null) { | |
jsContent += line; | |
} | |
inputStream.close(); | |
} catch (Exception e) { | |
throw new RuntimeException("Cannot read file" + e.getMessage()); | |
} | |
view.loadUrl("javascript:(" + jsContent + ")()"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment