Android New posture: how to intercept SMS

Source: Internet
Author: User

Company to do a "because it is confidential so can not say," The project, there is a need to intercept the mobile phone system text messages, and can not be displayed on the mobile phone text application.


OK, at first thought not difficult, on-line check the data also found someone did, so began to write demo, the results only found that this is a big hole ah!!


The first online search for the most implementation is the use of custom broadcastreceiver to intercept the "Android.provider.Telephony.SMS_RECEIVED" broadcast, it does not seem difficult, so tried. Found a good pit father Ah! No matter what happens to my cool big God, I can't intercept it.

Well, it must be that I wrote the code in the wrong posture, so I went to the Internet to check the information.


Ho ho ho, I really witty ~ ~ Suddenly found! It turns out that my priorities are not enough.

Android broadcasts are prioritized and broadcast with dynamic registrations has higher priority. So refer to the online, priority set to 2147483647, and get a dynamic registration, and then excited to use my cool pie to try again-but still no!

See: http://www.apkbus.com/forum.php?mod=viewthread&tid=53053


Depressed, is it the problem of my cell phone? OK, take a colleague's 2.3 Andro to try, really can ... Is it really a cell phone problem? No, take a few more tests. So I took another colleague's cell phone, and it was just like me. So presumably, the phone system version is not the same, because the other colleagues are more than 4.0 of the phone.


Well, it's a good reason to find out, but we gotta figure it out, right?


Although there is little information on the interception of text messages on the Internet, there are other ways to refer to them. Another way to do this is to delete the data from the SMS when the database is changed. That is, when new information is inserted, the new information is deleted, which is also intercepted.


Online information is to register a content provider to monitor "content://sms/" data changes, according to his code test, or can monitor the changes in the database.

See: http://bingtian.iteye.com/blog/641566

However, in more than 4.0 of the system cursor is actually empty (2.3 of the phone is no problem)!


Tut Good pit Daddy! What the hell is going on here?


Okay, patient. I think of another onchange (Boolean selfchange, Uri Uri), this method with URI parameter is only on the higher version of the Android system, so I have to print the URI here. The results found that the print is content://sms/910, content://sms/911 and the like, there is no content://sms/inbox. Then no wonder the cursor is empty!


Well, since Content://sms/inbox can't find it, I'll check the URI you gave me.


First, print out the field of the URI:

_id;thread_id;address;m_size;person;date;date_sent;protocol;read;status;type;reply_path_present;subject;body; Service_center;locked;sim_id;error_code;seen;ipmsg_id;ref_id;total_len;rec_len;iteminfoid;receive_date;

Compare this with the Content://sms/inbox field of the 2.3 system:

_id;thread_id;address;person;date;sc_timestamp;protocol;read;status;type;reply_path_present;subject;body; Service_center;locked;error_code;seen;lgemsgtype;lgesiid;lgecreated;lgeexpires;lgereceived;lgeaction;lgesec; Lgemac;lgedoc;doinstalled;lgepinremaincnt;index_on_icc;service_msg_sender_address;modified;modified_time;

Some fields are different, but some of the main fields, such as _id, address, body, are the same.

Then to get the content of the text message and the sender's number is still no problem, address is the sender number, body is the text message content. Try it, you can get it.


The worry is that you can delete the database in the text messages, but try it or can be ~


The result is also good--the success of the interception to SMS, and the text deleted, although the system will "ding ~" a reminder to SMS, but the display is not the text I just sent, but my last hair (just sent has been deleted).


Summary: Since can not be hanged in this tree, will find a few more lessons tree to try.

Android New posture: how to intercept SMS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.