Search in sources :

Example 1 with DWebView

use of wendu.dsbridge.DWebView in project xxf_android by NBXXF.

the class WrokWithFlyioTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wrok_with_flyio_test);
    DWebView dWebView = (DWebView) findViewById(R.id.webview);
    dWebView.addJavascriptObject(new Object() {

        /**
         * Note: This method is for Fly.js
         * In browser, Ajax requests are sent by browser, but Fly can
         * redirect requests to native, more about Fly see  https://github.com/wendux/fly
         * @param requestData passed by fly.js, more detail reference https://wendux.github.io/dist/#/doc/flyio-en/native
         * @param handler
         */
        @JavascriptInterface
        public void onAjaxRequest(Object requestData, CompletionHandler handler) {
            // Handle ajax request redirected by Fly
            AjaxHandler.onAjaxRequest((JSONObject) requestData, handler);
        }
    }, null);
    dWebView.loadUrl("file:///android_asset/fly.html");
}
Also used : DWebView(wendu.dsbridge.DWebView) JSONObject(org.json.JSONObject) CompletionHandler(wendu.dsbridge.CompletionHandler) JSONObject(org.json.JSONObject) JavascriptInterface(android.webkit.JavascriptInterface)

Example 2 with DWebView

use of wendu.dsbridge.DWebView in project xxf_android by NBXXF.

the class JavascriptCallNativeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_js_call_native);
    final DWebView dwebView = (DWebView) findViewById(R.id.webview);
    // set debug mode
    DWebView.setWebContentsDebuggingEnabled(true);
    dwebView.addJavascriptObject(new JsApi(), null);
    dwebView.addJavascriptObject(new JsEchoApi(), "echo");
    dwebView.loadUrl("file:///android_asset/js-call-native.html");
}
Also used : DWebView(wendu.dsbridge.DWebView)

Aggregations

DWebView (wendu.dsbridge.DWebView)2 JavascriptInterface (android.webkit.JavascriptInterface)1 JSONObject (org.json.JSONObject)1 CompletionHandler (wendu.dsbridge.CompletionHandler)1