close
Develipment checklist
程式中使用到 expansion file 的流程如下:
- 若你的 APK 超過 50MB,先決定哪些 resources 是可獨立拉出作為 main/patch expansion files。
- 修改程式邏輯使之可以存取位於外部儲存空間的 expansion files,建議使用 APK Expansion Zip Library 直接讀取 expansion file。
- 在程式的 main activity 加入邏輯,判斷程式開啟時 expansion file 是否有在 device 上,若沒有,則使用 Googple Play 的 Application Liscensing service 做 download 動作。建議使用 Downloader Livrary 實作下載行為。
Downloader Library
- Android 提供一套 Library 稱為 Downloader Library,幫你透過 LVL 索取 expansion file 的 URL、下載 expansion file、並執行檢查與容錯處理,甚至讓你可以暫停或回覆你的下載程序。你只需要在程式中加入少量的程式碼,即可呼叫 Downloader Library 幫你把工作完成。
- Downloader Library 會在 backgrounf service 執行下載 expansion file 的動作,打出 Notification 告訴 user 下載狀態,處理網路訊號不穩問題、支援暫停或回覆下載程序。
- 在你的程式中實作 Downloader Library 的方式如下:
- 實作一個繼承 Service 的 subclass。
- 實作一個繼承 BroadcastReceiver 的 subclass。
- 在 Main Activity 中加入邏輯判斷 expansion file 是否已成功下載,如果沒有,則呼叫 download process 與 display process UI。
- 實作 callback interface 以接收 download process 回傳的 updates。
Preparing to use the Downloader Library
首先必須透過 SDK Manager 下載 Downloader library。
- 開啟 Android SDK Manager,勾選 Google Play Licensing Library package 和 Google Play APK Expansion Library package 進行下載。
- 若你使用的是 Eclipse,執行以下步驟:
- Creat new project,選擇 Android Project from Existing Code
- Root Directory 選擇 <sdk>\extras\google\play_apk_expansion\downloader_library,按下 Finish。
- 同樣的步驟,再建立 <sdk>\extras\google\play_licensing\library 和 <sdk>\extras\google\play_apk_expansion\zip_file
- 在你的 Android 專案中,按右鍵點選 Properties,在 Android > Library 的 Panel,加入上述的三個 Library
- 若你使用 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
全站熱搜