phonegap示例在android模拟器中不起作用

时间:2013-06-13 13:29:25

标签: android cordova

我是编程phonegap应用程序的新手。我已经证明了一个简单的phonegap应用程序示例,并且可以在三星Galaxy Mini上正常工作,但不适用于Android模拟器。问题是,当我点击html中的特定按钮时,我想显示文字。

应用代码如下所示:

import android.os.Bundle;
import org.apache.cordova.*;

public class cordovaExample extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();

        MyClass js = new MyClass(this,appView);
        appView.getSettings().setJavaScriptEnabled(true);
        appView.addJavascriptInterface(js, "JS");

        super.loadUrl(Config.getStartUrl());
    }
}

public class MyClass 
{
     private WebView mAppView;
      private DroidGap mGap;
      Activity activity;

      public MyClass(DroidGap gap, WebView view)
      {
        mAppView = view;
        mGap = gap;
      }

      public String getText()
      {
          return "Hello World";
      }
}

HTML code:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />

        <title>Hello World</title>

         <script type="text/javascript" src="cordova-2.5.0.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
            function Showessage()
            {
             var element = document.getElementById('time');
             element.innerHTML = 'First Message :'+  window.JS.getText()  + '<br />';
              //alert('hello');
            }
        </script>
    </head>
    <body>
        <div class="app">
            <h1 class="event received" >Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received"  id ="time" onclick="Showessage()">Device is Ready</p>

            </div>
        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

你不必加载corodova.X.X.js只是cordova.js脚本。

所以包含应该是:

<script type="text/javascript" src="cordova.js"></script>
<!--- NOT  <script type="text/javascript" src="cordova-2.5.0.js"></script> -->