All Projects → smartzhao → X5Bridge

smartzhao / X5Bridge

Licence: Apache-2.0 license
Three party libraries of Tencent x5webview and JS interaction

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to X5Bridge

WebViewJavaScriptBridge
android webview javascript bridge
Stars: ✭ 24 (+41.18%)
Mutual labels:  webview, webviewjavascriptbridge
WeBer
Android x5 内核 WebView 的 Helper 完美兼容 AndroidX 和 android 库,欢迎使用~~~
Stars: ✭ 20 (+17.65%)
Mutual labels:  webview, x5
Android-Web-Inspector
How to Inspecting Android WebView, Network logs, XHR logs (including url request and parameter) and Element/DOM inspecting
Stars: ✭ 54 (+217.65%)
Mutual labels:  webview, webviewjavascriptbridge
x5 webview flutter
一个基于腾讯x5引擎的webview flutter插件,简化集成,一行代码打开视频播放,暂时只支持android使用
Stars: ✭ 90 (+429.41%)
Mutual labels:  webview, x5
Vanadium
Privacy and security enhanced releases of Chromium for GrapheneOS. Vanadium provides the WebView and standard user-facing browser on GrapheneOS. It depends on hardening in other GrapheneOS repositories and doesn't include patches not relevant to the build targets used on GrapheneOS.
Stars: ✭ 365 (+2047.06%)
Mutual labels:  webview
WebViewJavascriptBridge
This is a communication between Android applications and Web Javascript to establish a bridge between the call support each other
Stars: ✭ 16 (-5.88%)
Mutual labels:  webviewjavascriptbridge
Hybrid-Web-Platform
Full-fledged WebView as Xamarin.Forms plugin with cross-platform C# to JavaScript and JavaScript to C# calls support. Eventually invented for painless hybrid apps creation.
Stars: ✭ 19 (+11.76%)
Mutual labels:  webview
ClickableWebView
Simple WebView to Detect click on an image
Stars: ✭ 42 (+147.06%)
Mutual labels:  webview
Webview
Android WebView,Js互调
Stars: ✭ 22 (+29.41%)
Mutual labels:  webview
vscode-http-client
Simple way to do HTTP requests in Visual Studio Code.
Stars: ✭ 26 (+52.94%)
Mutual labels:  webview
Bloop
A light weight scratch pad inspired and derived from https://github.com/IvanMathy/Boop.
Stars: ✭ 54 (+217.65%)
Mutual labels:  webview
WebViewExample
work as a webview testing environment for frontend developers
Stars: ✭ 19 (+11.76%)
Mutual labels:  webview
UIFramework
A powerful UI framework for the game Onset (https://playonset.com/)
Stars: ✭ 13 (-23.53%)
Mutual labels:  webview
btt
Low level MacOS management in JavaScript via BetterTouchTool
Stars: ✭ 92 (+441.18%)
Mutual labels:  webview
nativescript-webview-interface
Plugin for bi-directional communication between webView and android/ios
Stars: ✭ 87 (+411.76%)
Mutual labels:  webview
TrendingCustomAlert
You can use a ready-made custom alert controller.
Stars: ✭ 25 (+47.06%)
Mutual labels:  webview
FlexHybridApp-Android
WebView bridge interface with Promise pattern
Stars: ✭ 20 (+17.65%)
Mutual labels:  webview
MHWebViewController
An Instagram inspired Web View Controller.
Stars: ✭ 75 (+341.18%)
Mutual labels:  webview
pdfjs
A sample for showing PDF files in a Xamarin.Forms application with pdf.js
Stars: ✭ 32 (+88.24%)
Mutual labels:  webview
electric-webview
Electric WebView is a scriptable WebView for developers.
Stars: ✭ 16 (-5.88%)
Mutual labels:  webview

X5Bridge

X5Bridge

The library of the bridge between Android native and JavaScript

Other communication interactions

Google native has a set of communication, in fact, it can also complete callback interaction, mainly through interface annotation. But JavaScript needs to define the global method Other communication interactions

Usage

JitPack.io

repositories {
    // ...
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation 'com.github.zorozhao:X5Bridge:0.1'
}

Use it in Java

add com.x5bridgelibrary.jsbridge.BridgeWebViewto your layout, it is inherited from WebView.

> manifests

            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.READ_PHONE_STATE" />
            <uses-permission android:name="android.permission.READ_SETTINGS" />
            <uses-permission
                android:name="android.permission.WRITE_SETTINGS"
                tools:ignore="ProtectedPermissions" />
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission
                android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
                tools:ignore="ProtectedPermissions" />
            <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

            <!-- Hardware acceleration is very important for X5 video playback. -->
            <uses-permission android:name="android.permission.GET_TASKS" />


> application

    X5bridgeManager.getInstance().preInitX5Core(this);

> activity

            MainActivity extends AppCompatActivity implements X5EventListener

            @Override
            public int obtainLayoutId() {
                return R.id.x5webview;
            }

            @Override
            public void onPageStarted(String url, Bitmap favicon) {
                Log.d(TAG, "onPageStarted: " + url);
            }

            @Override
            public void onPageFinished(String url) {
                Log.d(TAG, "onPageFinished: " + url);
            }

            public X5HandlerListener initX5HandlerListener() {
                  x5HandlerListener = X5bridgeManager
                      .getInstance()
                      .setX5EventListener(this)
                      .setActivity(MainActivity.this)
                      .getX5HandlerListener();
                 return x5HandlerListener;
    }

Register a Java handler function so that js can call

    x5HandlerListener.registerHandler("submitFromWeb", new BridgeHandler() {
        @Override
        public void handler(String data, CallBackFunction function) {
            Log.i(TAG, "handler = submitFromWeb, data from web = " + data);
            function.onCallBack("submitFromWeb exe, response data from Java");
        }
    });

js can call this Java handler method "submitFromWeb" through:

    WebViewJavascriptBridge.callHandler(
        'submitFromWeb'
        , {'param': str1}
        , function(responseData) {
            document.getElementById("show").innerHTML = "send get responseData from java, data = " + responseData
        }
    );

You can set a default handler in Java, so that js can send message to Java without assigned handlerName

        Already built in the three party Library
    //   webView.setDefaultHandler(new DefaultHandler());
    window.WebViewJavascriptBridge.send(
        data
        , function(responseData) {
            document.getElementById("show").innerHTML = "repsonseData from java, data = " + responseData
        }
    );

Register a JavaScript handler function so that Java can call

    WebViewJavascriptBridge.registerHandler("functionInJs", function(data, responseCallback) {
        document.getElementById("show").innerHTML = ("data from Java: = " + data);
        var responseData = "Javascript Says Right back aka!";
        responseCallback(responseData);
    });

Java can call this js handler function "functionInJs" through:

    x5HandlerListener.callHandler("functionInJs", new Gson().toJson(user), new CallBackFunction() {
        @Override
        public void onCallBack(String data) {

        }
    });

You can also define a default handler use init method, so that Java can send message to js without assigned handlerName

for example:

    bridge.init(function(message, responseCallback) {
        console.log('JS got a message', message);
        var data = {
            'Javascript Responds': 'Wee!'
        };
        console.log('JS responding with', data);
        responseCallback(data);
    });
    x5HandlerListener.send("hello");

will print 'JS got a message hello' and 'JS responding with' in webview console.

Notice

This lib will inject a WebViewJavascriptBridge Object to window object. So in your js, before use WebViewJavascriptBridge, you must detect if WebViewJavascriptBridge exist. If WebViewJavascriptBridge does not exit, you can listen to WebViewJavascriptBridgeReady event, as the blow code shows:

    if (window.WebViewJavascriptBridge) {
        //do your work here
    } else {
        document.addEventListener(
            'WebViewJavascriptBridgeReady'
            , function() {
                //do your work here
            },
            false
        );
    }

License

This project is licensed under the terms of the apache 2.0 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].