当前位置:编程学习 > JS >>

android WebView onJsAlert onJsConfirm

package com.html;

import com.sqlite.Dao.NcpRegisterDAO;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInte易做图ce;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;


public class Register_protocolActivity extends Activity {
  

    private Handler mHandler = new Handler();
    private WebView mWebView;
    private NcpRegisterDAO dao = null;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //踩上一脚,记录有了就知道复位的时候要去哪里
        dao = new NcpRegisterDAO(Register_protocolActivity.this);
        String name = "MainActivity";
        dao.add_Stepped(name);
        
        //隐藏标题栏
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        //隐藏状态栏
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //该ACTIVITY不需要layout设置,所以直接指向MainActivity的main
        setContentView(R.layout.protocol);
        //将WebView实例化
        mWebView = (WebView) this.findViewById(R.id.webView);
        //WebView打开权限
        mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        mWebView.getSettings().setJavaScriptEnabled(true);
        //WebView,SWF文件运行权限
        mWebView.getSettings().setPluginsEnabled(true);


        mWebView.addJavascriptInte易做图ce(new Action(), "ncp");  
     
       mWebView.loadUrl("file:///android_asset/protocol.html");

       
          
          // 创建WebViewChromeClient
               WebChromeClient wvcc = new WebChromeClient() {             
          // 处理Alert事件
             
             public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
              // 构建一个Builder来显示网页中的alert对话框
                             Builder builder = new Builder(Register_protocolActivity.this);
                                 builder.setTitle("计算1+2的值");
                                 builder.setMessage(message);
                                 builder.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
                                     @Override
                                     public void onClick(DialogInte易做图ce dialog, int which) {
                                         result.confirm();
                                     }
                                 });
                                builder.setCancelable(false);
                                 builder.create();
                                 builder.show();
                                 return true;
                             }
             
             
             // 处理Confirm事件
                     public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
                         Builder builder = new Builder(Register_protocolActivity.this);
                         builder.

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,