顯示具有 Android 標籤的文章。 顯示所有文章
顯示具有 Android 標籤的文章。 顯示所有文章

2012年3月3日 星期六

Android Linux開發環境配置(Old)

Android Linux開發環境配置  (舊文章整合筆記)
本文撰寫時,SDK的最新版本是3.0,ADT為r10。
需要項目
※目前版本的android SDK下載改成由android ADV Manager 來管理下載,
而不是直接下載SDK。




※請先配置好JDK與Eclipse請參考以下連結

Linux JDK配置。
Linux Sun JDK
Windwos JDK配置。
Linux Eclipse 配置。
Windows Eclipse配置。


android配置項目
a.下載SDK package
b.設定android SDK環境變數
c.安裝ADT
d.利用ADV下載android的SDK與開發工具。

詳細步驟
Step1.下載SDK package
//這個SDK package類含ADV Manager,下載完畢後會使用這個ADV來更新最新的SDK。
Ubuntu中FrieFox下載完後會再home的DownLoad裡。

Step2.解開SDK Package
  • tar xzf android-sdk_r10-linux_x86.tgz
使用桌面環境直接點擊解壓,或是使用命令模式解壓。

Step3.將解開後資料夾移到你習慣的資料夾
//suod mv [原本資料夾]  [目的資料夾]
sudo mv  [原本SDK資料夾]   /opt/androidSDK

Step4.SDK Package 環境變數設定
  • sudo gedit /etc/profile
於原本PATH中加入SDK Package的所在路徑如下:
    export PATH=${PATH}:<your_sdk_dir>/tools

Step5.Ubuntu 10.4 64bit
在64bit環境要使用32bit的android開發需要執行以下命令
If you are running a 64-bit distribution on your development machine, you need to install the ia32-libs package using apt-get::
  • sudo apt-get install ia32-libs

Step6.安裝ADT
  • Start Eclipse, then select Help > Install New Software...
  • Click Add, in the top-right corner.
  • In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location
https://dl-ssl.google.com/android/eclipse/
Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).
Click OK.

  • In the Available Software dialog, select the checkbox next to Developer Tools and click Next
  • In the next window, you'll see a list of the tools to be downloaded. Click Next
  • Read and accept the license agreements, then click Finish.
  • When the installation completes, restart Eclipse.

  • Eclipse中選Help > Install New Software 以便安裝ADT
  • 點擊ADD
  • Name 欄中輸入ADT Plugin ,Location欄中輸入 https (如果你https無法使用可以改成http)://dl-ssl.google.com/android/eclipse/
  • 接著一直Next到Finish之後重開Eclipse
  • Step7.ADT  Configuring (ADT的配置)
    1. Select Window > Preferences... to open the Preferences panel (Mac OS X: Eclipse > Preferences).
    2. Select Android from the left panel.
    3. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.
    4. Click Apply, then OK.
    Step8.平台的其他部件增加
  • From within Eclipse, select Window > Android SDK and AVD Manager.
  • On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute:
    android
  • 可以從Eclipse選項中 選 Window > Android SDK and AVD Manager   Or 或是直接從android SDK package解壓後所在直接執行 android
    執行完出現
    選擇你要安專的項目,請參考 http://developer.android.com/sdk/installing.html#which 之後就可以開始來寫個Hello World了哈~ 參考文件 SDK Install 官方文件 ADT install 官方文件

2011年5月10日 星期二

Android Application Components

Android 應用程式 構成要素

具有以下四種要素:
  • Activities (活動,前景執行的程序)
    • 一個Activity代表一個單一的螢幕與一個使用者介面。

    • 例如,一個email Application也許它有一個Activity用來顯示一個新的電子郵件列表(new email list),另一個Activity撰寫電子郵件,而另一個Activity則是讀取郵件,這些Activity work凝聚在一起形成了一個電子郵件應用程式,但其實每一個Activity都是獨立的,因此不同的Application可以啟動任一個Activities(如果電子郵件應用程序允許的話)。

    • 例如,攝影機的Application可以啟動email Application的new email的Activities,撰寫新的郵件,讓使用者可以分享圖片。

    • android中的任何activity都是Activity的子類,應用程式中屬於Activity的程序都需要extends Activity這個類或其子類,關於更多的Activities學習請參考Activities學習指南
  • Service(服務,背景執行的程序)
    • Service是一個Component,運作於背景,用來執行長時間運行的操作或是遠端操作的處理程序(remote process)。

    • service是不提供使用者操作介面的(在背景當然不需要囉)。

    • 例如:一個service在背景程序中執行音樂播放,而使用者在其他的Application中執行操作,也可能利用一個remote service經由網路取得資料而不干擾使用者正在進行互動的activity。

    • 其他的component,如一個activity,可以啟動service讓他運作或是綁定(bind)他,目的是為了讓他可以互動。


    • andorid中的service都是Service的子類,屬於service的程序都需要繼承Service或其子類,關於Service請參考Service開發指南
  • Content providers (內容提供者)
    • 一個Content providers管理一組共享的application資料。

    • 你能夠在檔案系統中儲存資料,一個SQLite資料庫在web上或其他持久性的的儲存位置,你的application可以存取。

    • 透由Content providers,其他的應用程式能夠查詢或是修改資料,如果內容供應者允許的話(if the content provider allows it)。

    • 例如,Android系統提供一個Content provider管理著用戶的內容資訊(contact information)。因此任何具有適當權限的應用程序可以查詢部分content providers(ContactsContract.Data)的讀取與寫入特定人的相關訊息。

    • content providers也用於私有的(private)讀取與寫入,在你的應用程式上並且不是分享的。例如,Note Pad應用程式使用一個content provider保存筆記。

    • Android中的content provider都是ContentProvider的子類,content provider除了實現了ContentProvider之外還需實現一套標準的API,使得其他程序能夠藉由API來交易取得資料,關於ContentProvider請參考ContentProvider開發指南

  • Broadcast receivers (廣播接收機)
    • 一個Brodcast receivers是一個component,他用來回應系統全部的廣播通知。

    • 許多廣播是源自於系統本身,例如,螢幕被關閉、電量不足、圖片被截取。

    • 應用程序也可以發出廣播訊息,例如,令其他的應用程式知道,有一些資料已經被下載到裝置上,是可以被使用的。

    • 雖然broadcast receivers不會顯示一個使用者介面,但他們可能會建立一個status bar notification (create a status bar notification)來提醒用戶一個廣播事件發生。

    • 更常見的是, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work.(做一個非常少量的工作)

    • For instance, it might initiate a service to perform some work based on the event.
      例如它可能會啟動一個service來執行一些基礎的工作。

    • Android的broadcase receiver都是BroadcastReceiver的子類,且每一個broadcast都會交付一個Intent物件,更多的訊息請看BroadcastReceiver Class。

Android Application Fundamentals

Android 應用基礎


Android的應用程式是使用Java程式語法撰寫的,程式的原始碼經由Android的SDK tools編譯成.apk檔,這個.apk檔案可以讓Android行動裝置安裝應用程式使用。

一但將應用程式安裝在行動裝置上,每一個Android的應用程式是存活在他自己的security sandbox裡。
  • Android的操作系統(指OS),是多使用者的Linux系統,每一個應用程式在Linux中都是不同的使用者。
  • 預設,每個應用程式在Linux中會有一個唯一的使用者ID,Linux會設定好檔案權限,讓應用程式只能操作屬於自己權限的檔案。
  • 每個程序都有他自己的虛擬機器(virtual machine , VM),應此每個應用程序運行是彼此隔離的。
  • 預設,每一個應用程式執行在自己的Linux process上。Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications
然而有一些方法可以讓兩個應用程式共享資源:
  • 可以安排兩個應用程序分享共同的Linux user ID,這樣他們就可以共用檔案文件,為了節省系統資源,也可將有共同用戶ID的應用程序安排運作在相同的Linux process,共享一個VM(應用程序必需簽署相同證書)。
關於Linux process請查閱計算機結構或作業系統書籍解釋。
  • 應用程式可以請求對於裝置設備、資料的存取權限,如用戶的聯繫人(user's contacts)、簡訊(SMS messages)、SD card、攝影機(camera)、藍芽(Bluetooth)、等等,所有的應用程式權限申請,發生在使用者安裝時期。

關於Android開發環境安裝請參考:
Android Linux上開發環境安裝

參考文件:
內容來自於Android官方開發指南文件,詳細內容請見