sencha touch 2與phonegap結合開發web app

來源:互聯網
上載者:User


1、下載sencha-touch-2-pr3和phonegap-1.3.0;

2、在assets(Java EE IDE)下面建立www, 然後在www下面建立js檔案夾,如下所示:

3、把sencha-touch-all.js和phonegap-1.3.0.js複製到js檔案夾下面;

4、在工程目錄下建立libs,把phonegap-1.3.0.jar複製到/libs下面;

5、把phonegap-1.3.0/Android下面的xml複製到/res下面;

6、下面修改代碼,修改後的代碼如下:

 

package huang.namespace;  /*import android.app.Activity*/; import android.os.Bundle; import com.phonegap.*; public class FirstAppActivity 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");     } }

(1)繼承Activity改成繼承DroidGap;
(2)注釋掉setContentView(R.layout.main);

    添加一行:super.loadUrl("file:///android_asset/www/index.html");
(3)注釋掉import android.app.Activity
(4)添加一行: import com.phonegap.*;
7、在AndroidManifest.xml中添加xml代碼,可以參考博文:http://www.apkbus.com/android-19083-1-1.html;

8、在js檔案夾下面再建立一個LocatCam.js,結果如所示:

LocatCam.js  /**  * @author huanghuang  */ Ext.application({ //    name:'LocatCam',     launch:function(){            Ext.create('Ext.Container', {                   fullscreen: true,                padding: 4,             //  width:'50%',                   items: [                {                   xtype:'button',                  ui: 'normal',                   text: 'photo',                  width:80,                  handler:function(){                 //     alert('hello my name is huanghuang!');                         // 等待載入PhoneGap                           document.addEventListener("deviceready", onDeviceReady, false);                                                       // PhoneGap載入完畢                           function onDeviceReady() {                               // 空                           }                                                      // 警告對話方塊被忽視                           function alertDismissed() {                               // 進行處理                           }                        navigator.notification.alert(                                   'You are the winner!',  // 顯示資訊                                   alertDismissed,         // 警告被忽視的回呼函數                                   'Game Over',            // 標題                                   'Done'                  // 按鈕名稱                               );                    }                 }            ]   });     } });

 

9、在www下面再建立index.html

index.html  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"                        "http://www.w3.org/TR/html4/strict.dtd">  <html>    <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <title>Capture Photo</title>          <!--import touch css and js -->     <link rel="stylesheet" href="resources/css/android.css" type="text/css" />          <script type="text/javascript" src="js/sencha-touch-all.js"></script>             <script type="text/javascript" charset="utf-8" src="js/phonegap-1.3.0.js"></script>      <script type="text/javascript" src="js/LocatCam.js"></script>    </head>    <body>    </body>  </html>

 

10、把sencha touch 2 下面的resources複製到www下面;

11、最後運行,可以看到結果

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.