I want to load a login page with JavaScript but I couldn't get the JavaScript to load even though i made a setJavaScriptEnabled(true)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://itsikkerhed.talentlms.com/index");
}
Try to enable DomStorage: webView.getSettings().setDomStorageEnabled(true);
Related
I am new to Android development and I am trying to make an app for my video website which has videos from YouTube.
The problem I am having right now is that the embedded iframe videos don't show the fullscreen button. I have been searching for a solution but have yet to find one that works for me.
mainActivity.java:
public class MainActivity extends Activity {
private WebView wv1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
WebView myWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
wv1=(WebView)findViewById(R.id.webView);
wv1.setWebChromeClient(new WebChromeClient() {
});
wv1.setWebViewClient(new MyBrowser());
wv1.loadUrl("http://m.youtube.com");
} .....
Thanks for any help.
I'm trying to make an app with a webview of facebook.com, i want to load custom css but i don't know how. I searched on Google but found old tutorials and i read that it has changed in Android Studio 2.0
Here is my code:
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.facebook.com/");
myWebView.setWebViewClient(new WebViewClient());
}
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView)findViewById(R.id.WebView1);
WebViewClient webViewClient = new WebViewClient();
webView.setWebViewClient(webViewClient);
webView.clearCache(true);
webView.getSettings().setUseWideViewPort(true);
webView.setInitialScale(1);
webView.getSettings().setBuiltInZoomControls(true);
webView.clearHistory();
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.setWebChromeClient(new WebChromeClient());
webView.addJavascriptInterface(new AudioInterface(this), "AndAud");
webView.loadUrl("file:///android_asset/web/index_SCORM.html");
}
}
I am trying to load the html5 scorm from the asset folder but the sound is not getting played on android. But in ios if I do the same the audio is getting played.
May I know the reason why this is happening?
I use the following to show a webpage in a webview
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
WebView webView = (WebView)findViewById(R.id.webView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setClickable(true);
webView.setFocusableInTouchMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webView.loadUrl("http://www.bbc.co.uk");
}
It works perfect and even has pinch and zoom however When i click to go to another webpage via a link it opens it in the default browser instead of the webview
How to i achieve this. I have read many articles on this but cant understand where i need to insert the commands
Any help appreciated
Mark
thanks very much for the link above the following works perfect
myWebView.loadUrl("http://someurl.com");
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
viewx.loadUrl(urlx);
return false;
}
});
I have this code which works to display a WebView and use it:
WebView webview = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
//setTheme(R.style.Theme_Sherlock_Light);
super.onCreate(savedInstanceState);
//setContentView(R.layout.podcasts);
webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(1);
webview.getSettings().setPluginState(PluginState.ON);
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
//webSettings.setBuiltInZoomControls(true);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
//webSettings.getMediaPlaybackRequiresUserGesture();
webSettings.setAllowContentAccess(true);
webSettings.setEnableSmoothTransition(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
setContentView(webview);
webview.loadUrl("url_to_go_to");
But when I try to use this code to point to a YouTube channel, it just shows a blank screen.
Any idea why that would happen?
Thanks!
In order to get HTML5 videos to show up you need to enable the following things in the WebView:
WebView view;
... //initialize WebView
WebSettings webViewSettings = view.getSettings();
view.setWebChromeClient(new WebChromeClient(){}); //just added this
webViewSettings.setDomStorageEnabled(true);
webViewSettings.setAppCacheEnabled(true);
webViewSettings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webViewSettings.setDatabaseEnabled(true);
webViewSettings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
You also need to put android:hardwareAccelerated="true" in your AndroidManifest. Otherwise, HTML5 stuff like YouTube videos won't work.