解析CDMA类型的短信
private static SmsMessage createFromPduCdma(byte[] pdu) throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
return createFromPdu(pdu, "com.android.internal.telephony.cdma.SmsMessage");
}
解析GSM或者CDMA类型的短信
private static SmsMessage createFromPdu(byte[] pdu, String className) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class<?> clazz = Class.forName(className);
Object object = clazz.getMethod("createFromPdu", byte[].class).invoke(clazz.newInstance(), pdu);
if (null != object) {
Constructor<?> constructor = SmsMessage.class.getDeclaredConstructor(Class.forName("com.android.internal.telephony.SmsMessageBase"));
constructor.setAccessible(true);
return (SmsMessage) constructor.newInstance(object);
} else {
return null;
}
}
注:相关教程知识阅读请移步到Android开发频道。










