Android PhoneGap to open a new Activity

后端 未结 2 856
说谎
说谎 2021-02-04 07:19

I have an html page loaded with PhoneGap. The html is mine and is on the phone, so I have full control of it.

I would like to click on a link on the html page to open a

2条回答
  •  终归单人心
    2021-02-04 07:39

    Create a new class:

    public class Variables {
    
        private WebView mAppView;
        private DroidGap mGap;
    
        public Variables(DroidGap gap, WebView view)
        {
            mAppView = view;
            mGap = gap;
        }
    
        public void changeActivity(){     
            Intent intent = new Intent(mGap, Example.class);
            mGap.startActivity(intent);
        }
    }
    

    in your main activity add:

    super.init();
    mc = new Variables(this, appView);
    appView.addJavascriptInterface(mc, "MyCls");
    

    in JavaScript call window.MyCls methods:

    function changeActivity() {
        window.MyCls.changeActivity();
    }
    

提交回复
热议问题