Search in sources :

Example 1 with BridgeWebView

use of com.github.lzyzsd.jsbridge.BridgeWebView in project JsBridge by lzyzsd.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (BridgeWebView) findViewById(R.id.webView);
    button = (Button) findViewById(R.id.button);
    button.setOnClickListener(this);
    webView.setWebChromeClient(new WebChromeClient() {

        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType, String capture) {
            this.openFileChooser(uploadMsg);
        }

        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType) {
            this.openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            mUploadMessage = uploadMsg;
            pickFile();
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
            mUploadMessageArray = filePathCallback;
            pickFile();
            return true;
        }
    });
    webView.addJavascriptInterface(new MainJavascrotInterface(webView.getCallbacks(), webView), "android");
    webView.setGson(new Gson());
    webView.loadUrl("file:///android_asset/demo.html");
    User user = new User();
    Location location = new Location();
    location.address = "SDU";
    user.location = location;
    user.name = "大头鬼";
    webView.callHandler("functionInJs", new Gson().toJson(user), new OnBridgeCallback() {

        @Override
        public void onCallBack(String data) {
            Log.d(TAG, "onCallBack: " + data);
        }
    });
    webView.sendToWeb("hello");
}
Also used : Gson(com.google.gson.Gson) OnBridgeCallback(com.github.lzyzsd.jsbridge.OnBridgeCallback) Uri(android.net.Uri) WebChromeClient(android.webkit.WebChromeClient) BridgeWebView(com.github.lzyzsd.jsbridge.BridgeWebView) WebView(android.webkit.WebView)

Example 2 with BridgeWebView

use of com.github.lzyzsd.jsbridge.BridgeWebView in project AgentWeb by Justson.

the class JsbridgeWebFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mBridgeWebView = new BridgeWebView(getActivity());
    mAgentWeb = AgentWeb.with(this).setAgentWebParent((ViewGroup) view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)).useDefaultIndicator(-1, 2).setAgentWebWebSettings(getSettings()).setWebViewClient(getWebViewClient()).setWebChromeClient(mWebChromeClient).setWebView(mBridgeWebView).setSecurityType(AgentWeb.SecurityType.STRICT_CHECK).createAgentWeb().ready().go(getUrl());
    initView(view);
    mBridgeWebView.registerHandler("submitFromWeb", new BridgeHandler() {

        @Override
        public void handler(String data, CallBackFunction function) {
            function.onCallBack("submitFromWeb exe, response data 中文 from Java");
        }
    });
    User user = new User();
    Location location = new Location();
    location.address = "SDU";
    user.location = location;
    user.name = "Agentweb --> Jsbridge";
    mBridgeWebView.callHandler("functionInJs", new Gson().toJson(user), new CallBackFunction() {

        @Override
        public void onCallBack(String data) {
            Log.i(TAG, "data:" + data);
        }
    });
    mBridgeWebView.send("hello");
}
Also used : BridgeWebView(com.github.lzyzsd.jsbridge.BridgeWebView) BridgeHandler(com.github.lzyzsd.jsbridge.BridgeHandler) Gson(com.google.gson.Gson) CallBackFunction(com.github.lzyzsd.jsbridge.CallBackFunction) LinearLayout(android.widget.LinearLayout)

Aggregations

BridgeWebView (com.github.lzyzsd.jsbridge.BridgeWebView)2 Gson (com.google.gson.Gson)2 Uri (android.net.Uri)1 WebChromeClient (android.webkit.WebChromeClient)1 WebView (android.webkit.WebView)1 LinearLayout (android.widget.LinearLayout)1 BridgeHandler (com.github.lzyzsd.jsbridge.BridgeHandler)1 CallBackFunction (com.github.lzyzsd.jsbridge.CallBackFunction)1 OnBridgeCallback (com.github.lzyzsd.jsbridge.OnBridgeCallback)1