的WebView方法不叫机器人 [英] WebView Methods is not called in android

查看:199
本文介绍了的WebView方法不叫机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web视图不调用javascript函数它返回警告像下面。任何人都可以提出如何摆脱下面的警告。

10月7日至30日:15:44.031:W / webview_proxy(3770):java.lang.Throwable中:警告:的WebView方法被调用的线程的WebViewCoreThread。所有的WebView方法必须在UI线程调用。的WebView的未来版本可能不支持在其他线程使用。

下面是我的职责。

 公共布尔onLongClick(视图v){
    的System.out.println(dfdsf);
    //告诉的JavaScript如果不选择模式来处理这个
    //if(!this.isInSelectionMode()){
        this.getSettings()setJavaScriptEnabled(真)。
        。this.getSettings()setJavaScriptCanOpenWindowsAutomatically(真);
        this.getSettings()setPluginsEnabled(真)。
        this.loadUrl(JavaScript的:android.selection.longTouch(););
        mScrolling = TRUE;
        //this.setJavaScriptEnabled(true);
    //}
    //不要让web视图处理它
    返回true;
}


解决方案

该警告是告诉你一切。您直接调用web视图的方法。这意味着你正在呼吁他们WebViewCoreThread。你必须给他们打电话的UI线程,这意味着在使用该web视图的活动。

我爱:

 的WebView WV =(的WebView)findViewById(ID);
wv.setJavaScriptEnabled(真);
wv.setJavaScriptCanOpenWindowsAutomatically(真);
wv.setPluginsEnabled(真);
wv.loadUrl(JavaScript的:android.selection.longTouch(););

My Web view is not calling the javascript function it is returning warning like below. Can anybody suggest how to get rid of the below warning.

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;
}

解决方案

The warning is telling you everything. You are calling the webview methods directly. That means you are calling them on WebViewCoreThread. You have to call them on the UI Thread that means in the Activity which uses this webview.

Like:

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

这篇关于的WebView方法不叫机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆