close

Develipment checklist

程式中使用到 expansion file 的流程如下:

  1. 若你的 APK 超過 50MB,先決定哪些 resources 是可獨立拉出作為 main/patch expansion files。
  2. 修改程式邏輯使之可以存取位於外部儲存空間的 expansion files,建議使用 APK Expansion Zip Library 直接讀取 expansion file。
  3. 在程式的 main activity 加入邏輯,判斷程式開啟時 expansion file 是否有在 device 上,若沒有,則使用 Googple Play 的 Application Liscensing service 做 download 動作。建議使用 Downloader Livrary 實作下載行為。

 

Downloader Library

  1. Android 提供一套 Library 稱為 Downloader Library,幫你透過 LVL 索取 expansion file 的 URL、下載 expansion file、並執行檢查與容錯處理,甚至讓你可以暫停或回覆你的下載程序。你只需要在程式中加入少量的程式碼,即可呼叫 Downloader Library 幫你把工作完成。
  2. Downloader Library 會在 backgrounf service 執行下載 expansion file 的動作,打出 Notification 告訴 user 下載狀態,處理網路訊號不穩問題、支援暫停或回覆下載程序。
  3. 在你的程式中實作 Downloader Library 的方式如下:
    1. 實作一個繼承 Service 的 subclass。
    2. 實作一個繼承 BroadcastReceiver 的 subclass。
    3. 在 Main Activity 中加入邏輯判斷 expansion file 是否已成功下載,如果沒有,則呼叫 download process 與 display process UI。
    4. 實作 callback interface 以接收 download process 回傳的 updates。

 

Preparing to use the Downloader Library

首先必須透過 SDK Manager 下載 Downloader library。

    1. 開啟 Android SDK Manager,勾選 Google Play Licensing Library package 和 Google Play APK Expansion Library package 進行下載。

      未命名1
    2. 若你使用的是 Eclipse,執行以下步驟:
      1. Creat new project,選擇 Android Project from Existing Code
        未命名1  
      2. Root Directory 選擇 <sdk>\extras\google\play_apk_expansion\downloader_library,按下 Finish。
        未命名1  
      3. 同樣的步驟,再建立 <sdk>\extras\google\play_licensing\library 和 <sdk>\extras\google\play_apk_expansion\zip_file
      4. 在你的 Android 專案中,按右鍵點選 Properties,在 Android > Library 的 Panel,加入上述的三個 Library
        未命名1  
    3. 若你使用 command line,執行以下指令以 update project

      android update project --path ~/Android/Myapp \

      --library ~/android_sdk/extras/google/play_apk_expansion/downloader_library \

      --library ~/android_sdk/extras/google/play_licensing/library \

      --library ~/android_sdk/extras/google/play_apk_expansion/zip_file

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 擒猿小舖 的頭像
    擒猿小舖

    擒猿小舖

    擒猿小舖 發表在 痞客邦 留言(0) 人氣()