开始新的活动时,HTML按钮在科尔多瓦点击 [英] Start new Activity when html button clicked in Cordova

查看:125
本文介绍了开始新的活动时,HTML按钮在科尔多瓦点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立与科尔多瓦和Java Android应用程序。
我想建立的意图时按钮,在HTML code点击了开始新的意图。

I am trying to build Android Application with Cordova and Java. I want to build intent that start a new Intent when button clicked in the HTML code.

这是我的HTML code:

This is my HTML code:

<!DOCTYPE html>
<html>
<head>
    <title>Demo Phonegap</title>
    <script type="text/javascript" charset="utf-8" src="cordova.js">
    </script>
</head>
<body>
<h2>Hello Android</h2>
<button onclick="openNewActivity()">test</button>
</body>
</html>

这是我的Java code:

And this is my Java code:

public class MyActivity extends DroidGap {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        super.loadUrl("file:///android_asset/www/index.html");
    }

    public void NewIntent()
    {
        Intent i = new Intent(this,HelpActivity.class);
        startActivity(i);
    }
}

我怎么能叫从HTML文件中NewIntent()无效无需构建插件。

How can I call the NewIntent() void from the html file without building plugin.

答案谢谢
哈伊姆。

Thanks for answers Haim.

编辑:我使用的PhoneGap我application.I的GUI要被点击的科尔多瓦HTML文件按钮时调用另一个活动

I using the phonegap for the GUI of my application.I want to call to another activity when button is clicked in the cordova html file.

推荐答案

我不知道为什么你需要开始在DroidGap的活动。但是,如果你想要的HTML的按钮点击执行一些原生Android code,你可以使用这种方法。

I don't know why you need to start an activity in DroidGap. But if you want to perform some native android code on Html's button click, you can use this approach.

您将不得不使用 JavascriptInterface 对的WebView。

You will have to use JavascriptInterface for WebView.

举例code片断:

//in onCreate 
appView.addJavascriptInterface(new MyJSInterface(),
            "myJSInterface");
super.loadUrl("file:///android_asset/www/index.html");


//JSInterface class
public class MyJSInterface {

    public MyJSInterface() {
        // TODO Auto-generated constructor stub
        Log.i(TAG, "constructor of jsinterface");
    }

    public void btnClick () {
        //do something
    }
}

而在你的HTML:

And in your html:

<button onclick="callFunction()">test</button>

在您的JS:

function callFunction(){
    myJSInterface.btnClick();
}

希望这有助于。

这篇关于开始新的活动时,HTML按钮在科尔多瓦点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆