Moto 双卡 指定卡发送短消息
phoneType =1 为GSM卡 0为CDMA卡
XT788实测可用.
public String sendMSG(String phone, String msg,int phoneType) { String Exp_string = ""; try { Class> smsManagerClass = null; Class[] divideMessagePamas = { String.class }; Class[] sendMultipartTextMessagePamas = { String.class, String.class, ArrayList.class, ArrayList.class, ArrayList.class, int.class }; Method divideMessage = null; Method sendMultipartTextMessage = null; smsManagerClass = Class.forName("android.telephony.MSimSmsManager"); Method method = smsManagerClass.getMethod("getDefault", new Class[] {}); Object smsManager = method.invoke(smsManagerClass, new Object[] {}); divideMessage = smsManagerClass.getMethod("divideMessage", divideMessagePamas); sendMultipartTextMessage = smsManagerClass.getMethod( "sendMultipartTextMessage", sendMultipartTextMessagePamas); ArrayListmagArray = (ArrayList ) divideMessage .invoke(smsManager, msg); sendMultipartTextMessage.invoke(smsManager, phone, "", magArray, null, null, phoneType); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "IllegalArgumentException"; } catch (IllegalAccessException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "IllegalAccessException"; } catch (InvocationTargetException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "InvocationTargetException"; } catch (ClassNotFoundException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "ClassNotFoundException"; } catch (SecurityException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "SecurityException"; } catch (NoSuchMethodException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "NoSuchMethodException"; } return Exp_string; }
列举API
public String checkapi(Context context) { String Exp_string = ""; try { Class> pkgClass = null; pkgClass = Class.forName("android.telephony.MSimSmsManager"); Method[] methods = pkgClass.getMethods(); for (Method m : methods) { // if (m.getName().contains(str)) { Exp_string = Exp_string + m.toGenericString() + "\n\n"; } } } catch (IllegalArgumentException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "IllegalArgumentException"; } catch (ClassNotFoundException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "ClassNotFoundException"; } catch (SecurityException e) { // TODO Auto-generated catch block // e.printStackTrace(); Exp_string = "SecurityException"; } return Exp_string; }
原作:飞雪