Git Product home page Git Product logo

mapleqin / webviewjavascriptbridge Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 4.0 428 KB

This is a communication between Android applications and Web Javascript to establish a bridge between the call support each other

Home Page: https://www.amphiaraus.org/WebViewJavascriptBridge

License: Apache License 2.0

Java 84.35% HTML 5.91% JavaScript 9.74%
webviewjavascriptbridge bridge web-javascript android javascript

webviewjavascriptbridge's Introduction

WebViewJavascriptBridge

This is a communication between Android applications and Web Javascript to establish a bridge between the call support each other

WebViewJavascriptBridge for Android Implement!

JavaScript

function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}

Sample

setupWebViewJavascriptBridge(function(bridge) {

    /* Initialize your app here */
    bridge.registerHandler('callJs', function(data, responseCallback) {
        console.log(data);
        responseCallback('callback:');
    })

    bridge.callHandler('callNative', "{\"callNativeData\":\"data\"}",function(data){
        console.log(data);
    })
})
WJBridgeWebView webVuew = new WJBridgeWebView(context);

webView.registerHandler("callNative", new WJBridgeHandler() {
        @Override
        public void handler(String data, WJCallbacks callbacks) {
            Toast.makeText(getApplicationContext(),data,Toast.LENGTH_SHORT).show();
            callbacks.onCallback("callNative response data" + System.currentTimeMillis());
        }
    });

webView.callHandler("callJs", "{\"callJsData\":\"data\"}", new WJCallbacks() {
        @Override
        public void onCallback(String data) {
            Toast.makeText(getApplicationContext(),"callJs callback" + data,Toast.LENGTH_SHORT).show();
        }
    });

Gradle Download

compile 'org.amphiaraus.webkit:jsbridge:[version]'

QQBrowser X5 core Download

compile 'org.amphiaraus.webkit:jsbridge-qqx5tbs:[version]'

Developed by

Amphiaraus - [email protected]

License

Copyright 2015 The Android Open Source Project for WebViewJavascriptBridge

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

webviewjavascriptbridge's People

Contributors

githubitpower avatar mapleqin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.