Android SIM card SMS Read/write

Source: Internet
Author: User

Since the API for reading and writing messages is hidden, we need to use the reflection method mentioned in the "learning of Java reflection mechanism " article to get the hidden API. There is a use case that everyone can download http://zhushou.360.cn/detail/index/soft_id/1608427

View Effects

Android Write SIM card SMS

/*** * 1) byte[] SMSC: The address of the SMS Service Center, which the individual believes can be empty during copying to the SIM card.      * 2) byte[] PDU: Chinese translation is the Protocol data unit, this parameter is the most important, we will explain in detail.  * 3) INT status: SMS stored in the status of the ICC card, there are 4 states, 1 is read, 3 is unread, 5 is sent, 7 is not sent. * @param smsc * @param PDU * @param status */public boolean WRITESMSTOICC (byte[] smsc,byte[] pdu,int status) {//mkeyboardhe Lper = new Reflectioninternal (This, "Android.telephony.SmsManager");//Call class, declare class, Mkeyboardview,mpasswordentry, //mkeyboardhelper.setint ("COPYMESSAGETOICC", 0) for the parameter to be passed, Boolean flag = false; Smsmanager Newsmsmanager = Smsmanager.getdefault (); try {Class smsmanagerclass = Class.forName (" Android.telephony.SmsManager "); Method Localmethod = Smsmanagerclass.getmethod ("COPYMESSAGETOICC", New Class[]{byte[].class,byte[].class,  Integer.type}); object[] arrayList = new Object[3];arraylist[0] = smsc;arraylist[1] = pdu;arraylist[2] = status;try {flag = ((Boolean) Localmethod.invoke (Newsmsmanager, ArrayList)). Booleanvalue (); catch (Illegalaccessexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} CAtch (IllegalArgumentException e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch ( InvocationTargetException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} catch (Nosuchmethodexception e) {//TODO auto-generated catch blocklog.e ("Nosuchmethodexception", " Nosuchmethodexception: "+ e.getmessage ()); E.printstacktrace ();} catch (ClassNotFoundException ex) {//TODO auto-generated catch blocklog.e ("ClassNotFoundException", " ClassNotFoundException: "+ ex.getmessage ()); Ex.printstacktrace ();} return flag;}

Android read SIM card SMS

Public arraylist<smsmessage> getsmslist () {arraylist<smsmessage> list = new arraylist<smsmessage> () ; Smsmanager Newsmsmanager = Smsmanager.getdefault (); try {class<?> smsmanagerclass = Class.forName (" Android.telephony.SmsManager "); Method Localmethod = Smsmanagerclass.getmethod ("GETALLMESSAGESFROMICC", null); try {list = (arraylist<smsmessage >) localmethod.invoke (Newsmsmanager, null);} catch (Illegalaccessexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch ( IllegalArgumentException e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch (InvocationTargetException E {//TODO auto-generated catch Blocke.printstacktrace ();}} catch (Nosuchmethodexception e) {//TODO auto-generated catch blocklog.e ("Nosuchmethodexception", " Nosuchmethodexception: "+ e.getmessage ()); E.printstacktrace ();} catch (ClassNotFoundException ex) {//TODO auto-generated catch blocklog.e ("ClassNotFoundException", " ClassNotFoundException: "+ ex.getmessage ()); ex.prIntstacktrace ();} return list;}


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.