Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法检测当前是否有弹出窗口显示在Android webview中?_Android_Webview - Fatal编程技术网

有没有办法检测当前是否有弹出窗口显示在Android webview中?

有没有办法检测当前是否有弹出窗口显示在Android webview中?,android,webview,Android,Webview,我有一个带有webview的Android应用程序,它显示一个表单,表单上有一堆控件。点击其中一个控件会显示一个弹出窗口。有没有办法检测网络视图中的弹出窗口当前是否处于活动状态?我做了两个假设,因为这个问题有点模糊: 案例1:弹出对话框显示 案例2:如广告中所示的弹出窗口 对于案例1: 我可以想出两种方法来解决这个问题 通过android文档,您可以调用isShowing()方法来确定是否显示对话框(弹出窗口),它将返回true 相反 根据有限的信息…您是否尝试过设置实现web界面类并调用一

我有一个带有webview的Android应用程序,它显示一个表单,表单上有一堆控件。点击其中一个控件会显示一个弹出窗口。有没有办法检测网络视图中的弹出窗口当前是否处于活动状态?

我做了两个假设,因为这个问题有点模糊:

  • 案例1:弹出对话框显示
  • 案例2:如广告中所示的弹出窗口
对于案例1: 我可以想出两种方法来解决这个问题

通过android文档,您可以调用isShowing()方法来确定是否显示对话框(弹出窗口),它将返回true

相反

根据有限的信息…您是否尝试过设置实现web界面类并调用一个函数来指示对话框是否显示?像这样

public class WebAppInterface {

Context mContext;

    /** Instantiate the interface and set the context */
    WebAppInterface(Context c) {
        mContext = c;
    }

    /** inform user that a dialog is being displayed */
    @JavascriptInterface
    public boolean dialogIsShowing() {
      //  Toast.makeText(mContext, "the dialog is showing!", Toast.LENGTH_SHORT).show();
return true
    }
}

//嵌入html以显示对话框的代码
函数showCranialsurgesDialog(){
Android.dialogIsShowing()
}
//处理对话框显示的结果
if(dialogIsShowing()==true){
//做点什么
}
对于案例2:如广告所示的弹出窗口
我的最佳猜测是使用: “webViewSettings.setJavaScriptCanOpenWindowsAutomatically(false)”方法。这会阻止窗口自动打开,这从理论上而不是从经验上可能会阻止您的问题。该文件是

最后,如果案例1是你坚持的,这可能也会有帮助

希望有帮助,
Jonny 2个盘子

您可以在活动的主要活动中使用

public void onWindowFocusChanged (boolean hasFocus) 
{
    WebView view = getCurrentFocus();
    String url = view.getUrl() ;
}

并检查它是否是相同的url连续两次

,据我所知,无法检测
网络视图中的任何弹出窗口。有一种方法可以在
WebView
中捕获一些事件,例如当用户点击链接并请求链接时。你应该考虑一下这个解决方案中的一些问题:谢谢你的回答。本质上,我指的弹出窗口是一个选项列表,当按下按钮时,它覆盖了webview显示的网页的其余部分。我需要这个来显示,但想知道它是什么时候显示,以便在这个时候处理的东西。我将仔细研究这些选项,看看是否可以组合一些内容。您需要将视图转换为WebView
public void onWindowFocusChanged (boolean hasFocus) 
{
    WebView view = getCurrentFocus();
    String url = view.getUrl() ;
}