android sim 卡短信读写
时间:2014-05-07 23:26:47
收藏:0
阅读:672
由于对短信读写操作的api 被隐藏了 , 我们需要使用《Java反射机制的学习》一文中提到的反射的方法得到隐藏API 。这有一个用例大家可以下载http://zhushou.360.cn/detail/index/soft_id/1608427
android写sim卡短信
/*** * 1) byte[] smsc : 短信服务中心的地址,个人认为在复制到SIM卡过程中可以为空。 * 2) byte[] pdu : 中文翻译是协议数据单元,这个参数最为重要,一会我们会做详细地解释说明。 * 3) int status : 短信存储在Icc卡上的状态,有4种状态,1是已读,3是未读,5是已发送,7是未发送。 * @param smsc * @param pdu * @param status */ public boolean writeSMStoIcc(byte[] smsc,byte[] pdu,int status){ // mKeyboardHelper = new ReflectionInternal(this,"android.telephony.SmsManager"); //调用类,声明类,mKeyboardView,mPasswordEntry,为需要传递的参数 // mKeyboardHelper.setInt("copyMessageToIcc", 0); 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 block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (NoSuchMethodException e) { // TODO Auto-generated catch block Log.e("NoSuchMethodException","NoSuchMethodException :"+ e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException ex) { // TODO Auto-generated catch block Log.e("ClassNotFoundException","ClassNotFoundException :"+ ex.getMessage()); ex.printStackTrace(); } return flag; }
android 读sim卡短信
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 block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (NoSuchMethodException e) { // TODO Auto-generated catch block Log.e("NoSuchMethodException","NoSuchMethodException :"+ e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException ex) { // TODO Auto-generated catch block Log.e("ClassNotFoundException","ClassNotFoundException :"+ ex.getMessage()); ex.printStackTrace(); } return list; }
评论(0)