Android當中的Mms對MMS(Multimedia Messaging Service)的操作關乎MMS協議部分都是通過Frameworks中提供的API來完成的:com.google.android.mms這個包在SDK中是不開放的,只能供內部程式使用,它封裝了所有MMS所需要的API。
這個包就是Android中對MMS協議的實現,包括一些資料結構:GenericPdu,MultimediaMessagePdu,SendReq,SendConf,NotificationInd,RetrieveConf,PduHeaders,PduBody,PduPart等。也包括操作這些資料的類:PduPersister,PduParser和PduComposer。PduPersister主要供給Android內部的應用程式使用;而PduParser和PduComposer會涉及到PDU相關的協議,會與MMSC或其他平台有相互影響(比如所打包的位元組流是否符合標準,能否被其他平台成功解析和識別等)
這個包的功能就是在發送時把多媒體資料打包成標準MMSC能識別的PDU格式資料,在接收時把PDU資料包解析出來以供更加方便的應用程式使用,同時也提供一些儲存上的介面,比如把PDU儲存到資料庫,從資料庫載入出PDU。
Class |
Purpose |
PduPersister |
用於管理PDU儲存 |
PduParser |
用於解析PDU |
PduComposer |
用於產生PDU |
PduPersister: 用於管理PDU儲存,關鍵的方法:
Return
|
Method
|
Description
|
PduPersister
|
getPduPersister(Context)
|
Get the object
|
Uri
|
persist(GenericPdu, Uri)
|
把一個GenericPdu儲存到Uri所指定的資料庫中,返回指向新產生資料的Uri
|
GenericPdu
|
load(Uri)
|
從資料庫把Uri所指的資料載入出來成一個GenericPdu對象
|
Uri
|
move(Uri, Uri)
|
把Pdu從一個地方移到另一個地方,比如從草稿箱移動到寄件匣,當MMS已發送時。
|
為什麼會要把PDU的儲存也封裝成PduPersister呢?因為PDU的儲存方式 是放在標準的SQLiteDatabase中,通過TelephonyProvider,而SQLiteDatabase中儲存不能以直接的PDU的位元組流來儲存,必須要把PDU拆解成為可讀的欄位,因此在儲存PDU和從儲存載入PDU的過程 中涉及到PDU資料上面的處理,因此封裝出來,更方便使用。
PduParser:用於把PDU位元組流解析成為Android可識別的GenericPdu
Return |
Method |
Description |
PduParser |
PduParser(byte[]) |
Construct an object |
GenericPdu |
parse() |
Parse the PDU byte stream into Android PDU GenericPdu |
PduComposer:把GenericPdu打包產生PDU位元組流
Return |
Method |
Description |
PduComposer |
PduComposer(Context, GenericPdu) |
Construct an object |
byte[] |
make() |
Transfer the GenericPdu into a PDU byte stream |