SMS Communication Library Lee, Chia-Peng 2015/12/09 Outline What - - PowerPoint PPT Presentation
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
Outline
- What can this lib do?
- Architecture
- Prerequisite
- Data structure
- How to use this lib?
- Example :
- Error reporting
- Reference
- API
FindMe!
What can this lib do?
- Record the SMS commands.
- Record interacting devices.
- Help parsing the command.
- Make developers focus on designing services.
CommandHandler # addExecutor Recorder Executor 1 Executor 2 … Database (Devices, Commands) SMS Service app SmsReceiver User input SMSCommunicate Executor filter
Architecture
Prerequisite
- 1. T
- ol : Eclipse + ADT
- 2. Media : JSONObject
- 3. Database : SQLite
- 1. Tool : Eclipse + ADT
http://www.eclipse.org/ http://developer .android.com/
- 2. Media : JSONObject
http://www.json.org/ JSONObject JavaDoc : http://www.json.org/javadoc/org /json/JSONObject.html
- 3. Database SQLite
http://www.sqlite.org/ Android Support API http://developer .android.com/reference/andro id/database/sqlite/SQLiteDatabase.html
Data structure (SQLite)
Device info : (可以在 String[] Recorder . DEVICES_TABLE_COLUMNS取得清單與順序) Command info : (可以用 String[] Recorder . COMMANDS_T ABLE_COLUMNS取得清單與順序)
Column name Data type Description id integer Primary key name varchar(32) Device’s display name phonenumber varchar(16) Device’s phonenumber 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)
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 “Executor”
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
- 1. Setting up environment
1 – a : Import library
1 – b : Set app permission
AndroidManifest.xml (before <application>)
1 – c : Register receiver to “SmsReceiver”
AndroidManifest.xml (Inside <application>)
- 2. Creating your own “Executor”
2 – a : Flow chart of message passing
SmsReceiver CommandHandler Executor SmsReceiver CommandHandler Executor Device A Device B (i) (ii) (iii) cnt : 0, role : 1 (true) cnt : 1, role : 0 (false) cnt : 2, role : 1 (true) cnt : 0, role : 0 (false) cnt : 1, role : 1 (true) cnt : 2, role : 0 (false)
2 – b : Implement “Executor” and recommended style
- 3. Initialize “Recorder” and
“CommandHandler”
3 – a : Initialize at the beginning of the program
3 – b : Accessing database via “Recorder”
3 – c : Add implemented executors
- 4. Invoke Executor
4 – a : Usual condition
4 – b : Dealing with asynchronous condition
Example : FindMe!
https://dl.dropbox.com/u/12632228/SMSDoc/downloads/FindMe.apk
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/
API – CommandHandler
# CommandHandler
static CommandHandler init(Context context) static CommandHandler getSharedRecorder() void Execute(String cmd, int device_id, int count, JSONObject usr_json)
API – Recorder Database
# Recorder Database
static Recorder init(Context context, String db_name) static Recorder getSharedRecorder() void deleteDevicesAndCommandsTable(SQLiteDatabase db)
API – Table “devices”
# 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)
API – Table “commands”
# 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)