[]typeScript Java互调问题

JAVA代码
————————————————————————————————
public class MainActivity extends Activity{
    
    private IPlugin mPlugin = null;
    private IPluginRuntimeProxy mProxy = null;
    boolean isLoad=false;
    boolean isExit=false;
    private WebView webView = null;
    private Activity activity = null;
    @Override    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        mProxy = new RuntimeProxy(this);
        mPlugin = new GameEngine(this);

        mPlugin.game_plugin_set_runtime_proxy(mProxy);
        mPlugin.game_plugin_set_option("localize","false");
        mPlugin.game_plugin_set_option("gameUrl", "http://10.0.0.114:8900/bin/index.html";);
        mPlugin.game_plugin_init();
        View gameView = mPlugin.game_plugin_get_view();
        this.setContentView(gameView);
        isLoad=true;
        
        webView  =  new WebView(this);
        activity = this;
        WebSettings webSettings = webView.getSettings();  
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);
 
        webView.addJavascriptInterface(new JSInvokeClass(), "js2java");
        
        webView.loadUrl("javascript:wave()");  
    }
    
    public final class JSInvokeClass {
        public void back() {
            // activity.finish();
            Log.d("mytest ","通过js调用的Java方法");
            Toast.makeText(activity, "通过js调用的Java方法", Toast.LENGTH_SHORT).show();
        }
    }
 
......................
————————————————————————————————————————————
 
TS 代码
————————————————————————

class LayaUISample {

    constructor() {
        Laya.init(1280, 720);

        sumToJava();


    }
}

function test() {
    console.log("java to js")
}
function sumToJava() {
    alert("js to java");
    js2java.back();
}
//程序入口
new LayaUISample();
declare var js2java : any;
 
————————————————————————————————
 
错误
05-17 11:33:53.949: E/LayaBox(31963): =====alert=js to java05-17 11:33:54.029: I/MonkVG(31963): Creating context 1024, 768, 2
05-17 11:33:54.039: E/LayaBox(31963): =====alert=http://10.0.0.114:8900/bin/js/LayaUISample.js:13: TypeError: Cannot read property 'back' of undefined
05-17 11:33:54.039: E/LayaBox(31963): window.js2java.back();
05-17 11:33:54.039: E/LayaBox(31963): ^
05-17 11:33:54.039: E/LayaBox(31963): TypeError: Cannot read property 'back' of undefined
05-17 11:33:54.039: E/LayaBox(31963): at sumToJava (http://10.0.0.114:8900/bin/js/LayaUISample.js:13:19)
05-17 11:33:54.039: E/LayaBox(31963): at new LayaUISample (http://10.0.0.114:8900/bin/js/LayaUISample.js:4:9)
05-17 11:33:54.039: E/LayaBox(31963): at eval (http://10.0.0.114:8900/bin/js/LayaUISample.js:16:1)
05-17 11:33:54.039: E/LayaBox(31963): at eval (native)
05-17 11:33:54.039: E/LayaBox(31963): at Document._downloadOk (apploader.js:5379:20)
05-17 11:33:54.039: E/LayaBox(31963): at apploader.js:5358:20
05-17 11:33:54.039: E/LayaBox(31963): at FileReader.filereader.onload (apploader.js:5937:47)

cuixueying

赞同来自:

我们看下,晚些回复!

要回复问题请先

商务合作
商务合作