System Monitor SDK (for Android) 開發者指南說明書 1. 技術項目簡介 經由簡化的應用程式介面 (Application Programming Interface), 可 提供給 Android 應用程式開發者開發基於 System monitor 的應用程式 2. 應用範圍說明 本技術可應用於具備 Android 系統 2.3.3 以上版本的 Android 嵌入式裝 置, 如 Android 手機,Android 機上盒等, 也可監控具備 Wi-Fi 功能之硬體的 Wi-Fi 使用情形
3. 安裝指南說明 3.1. 基本開發環境需求 採用 Windows XP/Vista/7, Mac OS X (intel) or Linux (i386) O.S 的 PC JavaSE JDK & JRE Version 5 or later, website: http://www.oracle.com/technetwork/java/javase/downloads/ Eclipse IDE Version 3.3(Europa) or later for JAVA Developer (including the Java Developer Tools (JDT), Web Developer Tooler (WDT) is included in the Eclipse installation package), website:http://www.eclipse.org Android SDK: download the appropriate package from following link, then read the guide to Install the Android SDK. website: http://developer.android.com/sdk/installing.html Android Development Tools plug-in for Eclipse, website: http://developer.android.com/ Android System Monitor SDK Library is in the SDK package.
3.2. 開發環境設定 本範例程式可在 Android 2.3 版 SDK AVD 模擬器或是 Android 1.6 版本以上之 手機上執行 3.2.1. 開發範例程式 Step 1. Open a android project with Eclipse or other Android IDE Step 2. Copy AndroidSystemMonitor.jar into folder libs Step 3. Select Project > Properties > Java Build Path Step 4. Click Add JARs button to select the AndroidSystemMonitor.jar file to the build path. Step 5. Click OK to finish Java Build path. Step 6. Add proper permission in manifest.xml, ex: android.permission.system_alert_window android.permission.write_external_storage Step 7. Register proper service into manifest.xml, ex: org.iii.systemmonitor.lib.cpuinfoservice org.iii.systemmonitor.lib.netcounterservice org.iii.systemmonitor.lib.memoryinfoservice org.iii.systemmonitor.lib.batterystatusservice org.iii.systemmonitor.lib.systemstatusmonitorservice Step 8. Register intent filter into manifest.xml: org.iii.systemmonitor.lib.systemstatusmonitorservice
3.2.2. 安裝範例程式 Step 1. To extract the III Android System Monitor SDK package of the folder to a convenient place on your computer. Step 2. To start Eclipse, run eclipse.exe found in the installation directory. Step 3. From the main menu bar, select File > Import... The Import wizard opens. Step 4. Select General > Existing Project into Workspace and click Next. Step 5. Choose either Select root directory or Select archive file and click the associated Browse to locate the directory or file containing the projects. Step 6. Under Projects select the project to import. Step 7. Click Finish to start the import. Step 8. Select Project > Properties > Java Build Path from the context menu on a created project or the File menu of the workbench. Step 9. Click Remove button to remove the selected folders from the class path. Step 10. Click Add JARs button to select the AndroidSystemMonitor.jar file to the build path. Step 11. Click OK to finish Java Build path. Your SDK example project development environment is now completed!
3.3. 執行範例程式 Step 1. Connect your Android device and it will show up in Eclipse. Step 2. Select Run As > Android Application, then Android System Monitor will run on your android device.
3.4. 範例程式操作說明 Step 1. 勾選任意複數欲監控的項目 (ex: CPU Loading, Memory, Wi-Fi, or Battery Status) 選項. Step 2. 勾選 Show on screen or write to log 選項 Step 3. 於輸入欄位輸入 Interval 秒數 Step 4. 按下 Start Monitoring 按鈕, 則即時的系統監控資訊會依照設定的時間間隔 (Interval) 顯示在螢幕或是寫入至手機, 儲存成 log 檔案 Step 4. 按下 Stop Monitoring 按鈕, 則停止系統監控 Step 5. 按下 View Log 按鈕, Step 6. 按下 View Graph 按鈕 Step 7. 使用連接線連接 PC 與手機, 開啟 Adroid SDK, 使用 ADB PULL 指令將儲存在手機的 Log 檔案複製到 PC 端 Step 8. 開啟 PC 端對應資料夾, 檢視 Log 檔是否存在 Step 9. 開啟 PC_Adroid_System_Monitor Step 10. 按下 Choose Log File 按鈕, 選擇對應的 Log 檔 Step 11. 按下 CPU Usage 按鈕 or Memory Usage 按鈕 or Network Usage Tx/Rx 按鈕 or Battery Level 按鈕 or Battery Temperature 按鈕, 則在 PC 端顯示監控資訊
4. 範例程式碼說明 本範例程式包含 IWannaUseSDKActivity.java 及 AndroidSystemMonitor.jar IWannaUseSDKActivity.java 程式碼撰寫重點如下 : 欄位宣告 : 一般性欄位宣告 Service 欄位宣告以及 ServiceConnection 欄位 宣告 mconnection: 此物件用來表示與 Service 之間建立的連線 dobindservice(): 此類方法建立 Activity.java 與 SystemStatusmotonitorSevice.class 之間的連線 getconnection(): 此類方法用來取得與 Service 之間建立的連線 dounbindservice(): 此類方法中斷 Activity.java 與 SystemStatusmotonitorSevice.class 之間的連線 StartService(): 此類方法用來開啟相對應的 Service StopService(): 此類方法用來關閉相對應的 Service tooglemonitorservice(boolean): 此類方法用來傳送相關監控設定至 SystemStatusmotonitorSevice.class showserviceview(int, boolean): 此類方法用以接收監控中的 Service 資訊
5.SDK 與 Function List API 說明 5.1. SystemStatusMonitorService Class Overview The class is to manage the system monitoring, which can get the setting about what is intend to monitor, and start or stop the monitoring. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver and stop monitoring IBinder onbind(intent intent) Return incoming messenger with getbinder() 5.2. CpuInfoService Class Overview The class is to get and parse the system information of CPU and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver void parsetopinfo () To parse the information and send it within intent by broadcast
5.3. MemoryInfoService Class Overview The class is to get and parse the system information of Memory and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver void parsememinfo () To parse the information and send it within intent by broadcast 5.4. NetCounterService Class Overview The class is to get and parse the system information of Wi-Fi Net Counter and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver void parserxresult () To parse the information and send it within intent by broadcast void parsetxresult () To parse the information and send it within intent by broadcast
5.4. BatteryStatusService Class Overview The class is to get and parse the system information of Battery Status and send it to System Status Monitor Service. Public Method List void oncreate() Use to get shared preference setting and do init() int onstartcommand(intent intent, int flags, int startid) Start monitoring with information from intent void ondestroy() Unregister receiver to status monitor receiver 6. 參考文獻 Android SDK & Developer Guide http://developer.android.com/guide/basics/what-is-android.html