ArticleDirectory
- 3.1 Short Message
- 3.2 sending and receiving
The SMS structure and main fields of Android are as follows:
Others Code
-
- _ Id // Short Message serial number
-
- Thread_id // The Conversation sequence number (conversation)
-
- Address // recipient
-
- Person // sender
- Date // Date
-
- Protocol // Protocol
-
- Read // read
-
- Status // status
-
- Type // type
-
- Reply_path_present //
-
- Subject // topic
- Body // Short Message Content
-
- Service_center // Service Center
_ Id // short message No. thread_id // conversation No. (conversation) address // recipient person // sender date // Date protocol // Protocol read // whether to read status // status type // type reply_path_present // subject // topic body/Short Message content service_center // Service Center
2. Get short messages from the machine.
See the code, which is relatively simple:
Java code
-
- SMS =NewArraylist <Map <string, Object> ();
- Cursor c = getcontentresolver (). Query (urisms,Null,Null,Null,
-
- Null);
-
- While(C. movetonext ()){
-
- Try{
-
- Item =NewHashmap <string, Object> ();
-
- // Read the contents of the SMS;
-
- For(IntI =0; I <C. getcolumncount (); I ++ ){
-
- String strcolumnname = C. getcolumnname (I );
-
- String strcolumnvalue = C. getstring (I );
-
- Item. Put (strcolumnname, strcolumnvalue );
-
- }
-
- }Catch(Exception e ){
-
- Log. W ("Exception :", E. getmessage ());
-
- }
-
- SMS. Add (item );
SMS = new arraylist <Map <string, Object> (); cursor c = getcontentresolver (). query (urisms, null); While (C. movetonext () {try {item = new hashmap <string, Object> (); // read the contents of the SMS; For (INT I = 0; I <C. getcolumncount (); I ++) {string strcolumnname = C. getcolumnname (I); string strcolumnvalue = C. getstring (I); item. put (strcolumnname, strcolumnvalue) ;}} catch (exception e) {log. W ("exception:", E. getmessage ();} SMS. add (item );
3. Conclusion 3.1 Short Message
In Android, there are many short message fields, but not every field is required.
3.2 sending and receiving
3.2.1 send Short Messages
It is relatively simple to send short messages, and there is a send method directly for the API. It should be noted that the length of Short Messages is controlled and the sending status is obtained.
3.2.2 receive short messages
The main idea is to register as a service and listen to system notifications when new messages are received, and then perform subsequent operations. There are a lot of online code and I will not discuss it much.