sms communication library
play

SMS Communication Library Lee, Chia-Peng 2015/12/09 Outline What - PowerPoint PPT Presentation

PCS Term Project: SMS Communication Library Lee, Chia-Peng 2015/12/09 Outline What can this lib do? Architecture Prerequisite Data structure How to use this lib? Example : FindMe! Error reporting Reference


  1. PCS Term Project: SMS Communication Library Lee, Chia-Peng 2015/12/09

  2. Outline • What can this lib do? • Architecture • Prerequisite • Data structure • How to use this lib? • Example : FindMe! • Error reporting • Reference • API

  3. What can this lib do? • Record the SMS commands. • Record interacting devices. • Help parsing the command. • Make developers focus on designing services.

  4. Architecture SMSCommunicate Executor Recorder Database (Devices, Executor 1 Commands) Executor 2 … CommandHandler # addExecutor SMS Service app SmsReceiver filter User input

  5. Prerequisite 1. T ool : Eclipse + ADT 2. Media : JSONObject 3. Database : SQLite

  6. 1. Tool : Eclipse + ADT http://www.eclipse.org/ http://developer .android.com/

  7. 2. Media : JSONObject http://www.json.org/ JSONObject JavaDoc : http://www.json.org/javadoc/org /json/JSONObject.html

  8. 3. Database SQLite http://www.sqlite.org/ Android Support API http://developer .android.com/reference/andro id/database/sqlite/SQLiteDatabase.html

  9. Data structure (SQLite) Device info : ( 可以在 String[] Recorder . DEVICES_TABLE_COLUMNS 取得清單與順序 ) Column name Data type Description id integer Primary key name varchar(32) Device ’ s display name phonenumber varchar(16) Device ’ s phonenumber Command info : ( 可以用 String[] Recorder ABLE_COLUMNS 取得清單與順序 ) . COMMANDS_T Column name Data type Description id integer Primary key timestamp timestamp Created timestamp count integer age of msg role boolean Active(TRUE)/Passive(FALSE) device_id integer From/to which device command varchar(16) Command name content varchar(512) Content (JSONString)

  10. How to use this lib? 1. Setting up environment a) Import library b) Set app permission c) Register receiver to “ SmsReceiver ” 2. Creating your own “E xecutor ” a) Flow chart of message passing b) Implement “ Executor ” and recommended style 3. Using “ Recorder ” and “ CommandHandler ” a) Initialize at the beginning of the program b) Accessing database via “ Recorder ” c) Add implemented executors 4. Invoke Executor a) Usual condition b) Dealing with asynchronous condition

  11. 1. Setting up environment

  12. 1 – a : Import library

  13. 1 – b : Set app permission AndroidManifest.xml (before <application>)

  14. 1 – c : Register receiver to “ SmsReceiver ” AndroidManifest.xml (Inside <application>)

  15. 2. Creating your own “E xecutor ”

  16. 2 – a : Flow chart of message passing Device A Device B (ii) (i) SmsReceiver SmsReceiver CommandHandler CommandHandler (iii) Executor Executor cnt : 0, role : 1 (true) cnt : 0, role : 0 (false) cnt : 1, role : 0 (false) cnt : 1, role : 1 (true) cnt : 2, role : 1 (true) cnt : 2, role : 0 (false)

  17. 2 – b : Implement “E xecutor ” and recommended style

  18. 3. Initialize “ Recorder ” and “ CommandHandler ”

  19. 3 – a : Initialize at the beginning of the program

  20. 3 – b : Accessing database via “Recorder”

  21. 3 – c : Add implemented executors

  22. 4. Invoke Executor

  23. 4 – a : Usual condition

  24. 4 – b : Dealing with asynchronous condition

  25. Example : FindMe! https://dl.dropbox.com/u/12632228/SMSDoc/downloads/FindMe.apk

  26. Reference: • SmsCommunicateLibrary.jar http://tinyurl.com/smsclibv1-0 • SmsCommunicateLibrary JavaDoc http://tinyurl.com/smsclibjavadoc • Android Developer http://developer .android.com/ • Android Package JavaDoc http://developer .android.com/reference/ • SQLite http://www.sqlite.org/ • Eclipse http://www.eclipse.org/

  27. API – CommandHandler # CommandHandler static CommandHandler init(Context context) static CommandHandler getSharedRecorder() void Execute(String cmd, int device_id, int count, JSONObject usr_json)

  28. API – Recorder Database # Recorder Database static Recorder init(Context context, String db_name) static Recorder getSharedRecorder() void deleteDevicesAndCommandsTable(SQLiteDatabase db)

  29. API – Table “ de vices” # T able “ devices ” void changeDeviceNameById(SQLiteDatabase db, int device_id, String new_name) void createDevice(SQLiteDatabase db, String name, String phonenumber) void deleteDeviceById(SQLiteDatabase db, int device_id) void deleteDeviceByPhonenumber(SQLiteDatabase db, String phonenumber) Object[][] getAllDevices(SQLiteDatabase db) Object[] getDeviceByID(SQLiteDatabase db, int device_id) int getDeviceIdByPhonenumberOrCreate(SQLiteDatabase db, String phonenumber)

  30. API – Table “ c ommands” # T able “ commands ” void saveCommand(SQLiteDatabase db, boolean role, int device_id String command , String content) void createDevice(SQLiteDatabase db, String name, String phonenumber) void deleteCommandById(SQLiteDatabase db, int command_id) void deleteCommandByDeviceId(SQLiteDatabase db, int device_id) Object[][] getAllCommands(SQLiteDatabase db)

Recommend


More recommend