WrokWithFlyioTestActivity.java 1.38 KB
Newer Older
gao.chao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
package com.mayi.demo.web;

import android.os.Bundle;
import android.webkit.JavascriptInterface;

import androidx.appcompat.app.AppCompatActivity;

import com.mayi.demo.R;
import com.mayi.fastdevelop.web.CompletionHandler;
import com.mayi.fastdevelop.web.DWebView;

import org.json.JSONObject;


public class WrokWithFlyioTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wrok_with_flyio_test);
        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");
    }
}