Calling javascript function from the android activity

前端 未结 2 2108
终归单人心
终归单人心 2021-01-06 07:59

I am using the following code in the main activity , its giving the function display() is not defined

public class cordovaExample extends DroidGap {
    Cont         


        
2条回答
  •  半阙折子戏
    2021-01-06 08:42

    From Cordova 2.6 you can override onMessage in your CordovaActivity (DroidGap), you have to capture the message "onPageFinished", then you can call any function declared on the document:

    @Override
    public Object onMessage(String id, Object data) {
        if("onPageFinished".equals(id)) {
            sendJavascript("display('abc');");
        }
        return super.onMessage(id, data);
    }
    

    And in the HTML:

    
    

    Other option is to call it in the onResume() function of the CordovaActivity:

    @Override
    public void onResume() {
        super.onResume();
        sendJavascript("display('abc');");
    }
    

提交回复
热议问题