WebView methods are not called in android

My webview does not call the javascript function, it returns a warning as shown below. Can anyone suggest how to get rid of the warning below.

07-30 10:15:44.031: W/webview_proxy(3770): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.

Below is my function.

 public boolean onLongClick(View v){ System.out.println("dfdsf"); // Tell the javascript to handle this if not in selection mode //if(!this.isInSelectionMode()){ this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setPluginsEnabled(true); this.loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; //this.setJavaScriptEnabled(true); //} // Don't let the webview handle it return true; } 
+7
android methods webview
source share
6 answers

A warning tells you everything. You directly call webview methods. This means that you are invoking them in WebViewCoreThread. You must call them in the user interface thread, which means in the Activity that this webview uses.

how

 WebView wv = (WebView)findViewById(id); wv.setJavaScriptEnabled(true); wv.setJavaScriptCanOpenWindowsAutomatically(true); wv.setPluginsEnabled(true); wv.loadUrl("javascript:android.selection.longTouch();"); 
+6
source share

As the warning says, you are calling webview methods in WebViewCoreThread . So change your code like this:

 public boolean onLongClick(View v){ YourActivity.this.runOnUiThread(new Runnable() { public void run() { this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setPluginsEnabled(true); this.loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; } }); } 
+15
source share

Use this code. I think it will work for you, and changed it to suit your needs ##

  private WebView webView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.web); webView = (WebView) findViewById(R.id.web_view); webView.setInitialScale(1); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(false); webView.loadUrl("http://www.youtube.com"); } } 
+2
source share

is onLongClick a member of web browsing?

It seems you cannot call all the WebView methods in the 'WebViewCoreThread' thread.

You can use the handler, send the msg message to the onLongClick handler, and then call the WebView methods in your handler.

0
source share

I think you should execute your onLongClick method code in runOnUIThread () or using Handler, this warning should use all this in the workflow.

0
source share

you can use webview through runnable. No need to use activity.

  webView.post(new Runnable() { @Override public void run() { getSettings().setJavaScriptEnabled(true); getSettings().setJavaScriptCanOpenWindowsAutomatically(true); getSettings().setPluginsEnabled(true); loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; } }); 
0
source share

All Articles