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;}