2012年7月31日 星期二

一起來玩 X86 版本的 Android 4.0.4 (Ice Cream Sandwich branch)


最近在搞 X86 版本的 Android,目前用的是由 cwhuang (黃志偉) 等開發者維護的 Android-x86。

根據 "ReleaseNote 4.0-RC2" 這篇文章,下載 Ice Cream Sandwich 的程式碼:

$ repo init -u http://git.android-x86.org/manifest -b ics-x86
$ repo sync 

由於我打算先用 VMware Player 和 VirtualBox 來執行 Android 4.0。所以在編譯時,選擇的裝置是 eeepc:

$ lunch eeepc-eng
$ make iso_img 

接著請耐心等待它編譯完成。編譯 Android 4.0 比起編譯 Android 2.3 更花時間,所以建議參考 android.com 上的說明設定使用 CCACHE,可以讓再次編譯時稍快一些。不過,使用 CCACHE 在第一次編譯時似乎會拉長需要的時間。

編譯完成後,可以得到 out/target/product/eeepc/eeepc.iso 這個檔案。接著,可以利用 VMware Player 或 Virtualbox 建立一個虛擬機器,並執行這個 ISO 檔。

載入 Android 4..0 後,使用 ethernet 前必須設定 eth0 的 IP,可以開啟一個 Terminal,先執行 su 取得 root 權限,然後執行 dhcpcd eth0 或 netcfg eth0 dhcp 來取得 IP 位址。也要使用 setprop 指令設定 net.dns1,我目前慣用 8.8.8.8 這個伺服器。

然後就可以開始瀏覽網頁了,也可以在 Windows 端開個 DOS 視窗,利用 adb 指令連進來。



補充一點,VMware Player 若採用預設的選項建立虛擬機器,會發現啟動 Android 4.0 後無法使用 eth0 這個介面。這時,請關閉虛擬機器,然後修改 .vmx 檔,將 ethernet0.virtualDev 改成 "vlance"。


2012年7月29日 星期日

Web App設計- Web 和Android的互動技巧


上圖是Android官方網站介紹如何在手機上利用HTML, CSS等網頁技術來設計Web APPs,最簡單的方法和傳統的PC瀏覽網頁一樣,使用一般的網頁設計,把網頁放在伺服器上,然後利用瀏覽器來閱讀,如上圖左邊方式。今天我們要來討論的是如何整合網頁及Android APP,如上圖右邊的方式,這種方式有一種讓人期待和創新的設計。
1. 先建立一個專案
2. 刪除TextView,新增WebView
3. 修改程式
package com.example.webtest;
import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends Activity {
    WebView web;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        web = (WebView) findViewById(R.id.webView1);
        WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web.loadUrl("file:///mnt/sdcard/test.html");
        web.addJavascriptInterface(new JavaScriptInterface(this), "Android");
       
    }
 
}
4. 新增JavaScriptInterface.java,並加入下列程式。

package com.example.webtest;
import android.content.Context;
import android.widget.Toast;
public class JavaScriptInterface {
    Context mContext;
    /** Instantiate the interface and set the context */
    JavaScriptInterface(Context c) {
        mContext = c;
    }
    /** Show a toast from the web page */
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    }
}


5. 在AndroidManifest.xml檔中加入Internet使用權限。
6.用記事本編輯,並儲存為test.html
Test/title></span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; "><body>Hello World</span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; "><input type="button" value="Say hello" </span><span style="font-family: Calibri; ">onClick</span><span style="font-family: Calibri; ">="</span><span style="font-family: Calibri; ">showAndroidToast</span><span style="font-family: Calibri; ">('Hello Android!')" /></span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; "><script type="text/</span><span style="font-family: Calibri; ">javascript</span><span style="font-family: Calibri; ">"></span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; ">    function </span><span style="font-family: Calibri; ">showAndroidToast</span><span style="font-family: Calibri; ">(toast) {</span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; ">        </span><span style="font-family: Calibri; ">Android.showToast</span><span style="font-family: Calibri; ">(toast);</span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; ">    }</span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; "></script></span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; "></body></span></p> <p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; "></html></span></p><p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="font-family: Calibri; ">7.利用DDMS</span><span style="background-color: white; font-family: 新細明體; ">開啟</span><span style="background-color: white; font-family: Calibri; ">File explorer</span><span style="background-color: white; font-family: 新細明體; ">在</span><span style="background-color: white; font-family: Calibri; ">sdcard</span><span style="background-color: white; font-family: 新細明體; ">上放</span><span style="background-color: white; font-family: Calibri; ">test.html</span><span style="background-color: white; font-family: 新細明體; ">檔案。</span></p><p class="separator" style="text-align: center; clear: both; "><a imageanchor="1" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv1GTN14kMO_ZWsCgRNVAjne9YOdXsxlWHnT1lDYxEX3gcepLZNQFViBH4tG6uvZC5XYwjx8iFtqa-TE4nz6U068xJommb6yj7YVp7Rg04cnqhBnYBxE7zyVGdXPHGSvWZ1y8Bqn3BXvkz/s1600/web4.png" style="margin-left: 1em; margin-right: 1em; "><img style="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv1GTN14kMO_ZWsCgRNVAjne9YOdXsxlWHnT1lDYxEX3gcepLZNQFViBH4tG6uvZC5XYwjx8iFtqa-TE4nz6U068xJommb6yj7YVp7Rg04cnqhBnYBxE7zyVGdXPHGSvWZ1y8Bqn3BXvkz/s320/web4.png" border="0" width="320" height="272"></a></p><p class="separator" style="text-align: left;clear: both; ">8. 執行結果</p><p class="separator" style="text-align: center; clear: both; "><a imageanchor="1" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO1OtNxeYa6GsYhWCXTPYytIO7qVhTp1E97M5_nY-QdEq5O86OLweskw9U2M95WZ_1zFf5EkC1Kc1BZ8hhAVd4x-ICUWHHpHAoELNKtzeGZHTcNDImrRZ8cETQtVUkszmr2s_nkLmd9YwB/s1600/web5.png" style="margin-left: 1em; margin-right: 1em; "><img style="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO1OtNxeYa6GsYhWCXTPYytIO7qVhTp1E97M5_nY-QdEq5O86OLweskw9U2M95WZ_1zFf5EkC1Kc1BZ8hhAVd4x-ICUWHHpHAoELNKtzeGZHTcNDImrRZ8cETQtVUkszmr2s_nkLmd9YwB/s320/web5.png" border="0" width="191" height="320"></a></p><p class="separator" style="text-align: left;clear: both; "><br></p><p style="margin-top: 4.8pt; margin-bottom: 0pt; margin-left: 0in; text-indent: 0in; direction: ltr; unicode-bidi: embed; word-break: normal; "><span style="background-color: white; font-family: 新細明體; "><br></span></p><p></p><div><br></div>

2012年7月28日 星期六

解決DMA-210L開發平台在Ubuntu 12.04 LTS下編譯Android 2.3.4出現的問題


近日因緣際會測試到長高科技的 ARM Cortex A8 DMA-210L開發平台,由於該平台目前使用的是Android 2.3.4(Gingerbread)作業系統,加上Gingerbread在Ubuntu 12.04編譯上有些許地方需要修改,在這裡整理出來順便做個紀錄。