android 双卡手机发短信/判断手机是否为双卡

通过反射发现sendMultipartTextMessage多了一个phoneType的参数,这个参数就是这只用GMS还是CDMA卡发送的。

phoneType获取方法,iTelephony.getActivePhoneType();//1=GSM,2=CDMA

  1. try {  
  2.            
  3.         Class<?> smsManagerClass = null;   
  4.         Class[] divideMessagePamas = { String.class };   
  5.         Class[] sendMultipartTextMessagePamas = { String.class,String.class, ArrayList.class, ArrayList.class,ArrayList.class, int.class };   
  6.         Method divideMessage = null;   
  7.         Method sendMultipartTextMessage = null;   
  8.         smsManagerClass = Class.forName("android.telephony.SmsManager");   
  9.         Method method = smsManagerClass.getMethod("getDefault", new Class[]{});   
  10.         Object smsManager = method.invoke(smsManagerClass, new Object[]{});   
  11.         divideMessage = smsManagerClass.getMethod("divideMessage",divideMessagePamas);   
  12.         sendMultipartTextMessage = smsManagerClass.getMethod("sendMultipartTextMessage", sendMultipartTextMessagePamas);   
  13.         ArrayList<String> magArray = (ArrayList<String>) divideMessage.invoke(smsManager, content);   
  14.      
  15.         sendMultipartTextMessage.invoke(smsManager,phone, "", magArray, null, null,phoneType);  
  16.     } catch (IllegalArgumentException e) {  
  17.         // TODO Auto-generated catch block  
  18.         e.printStackTrace();  
  19.     } catch (IllegalAccessException e) {  
  20.         // TODO Auto-generated catch block  
  21.         e.printStackTrace();  
  22.     } catch (InvocationTargetException e) {  
  23.         // TODO Auto-generated catch block  
  24.         e.printStackTrace();  
  25.     } catch (ClassNotFoundException e) {  
  26.         // TODO Auto-generated catch block  
  27.         e.printStackTrace();  
  28.     } catch (SecurityException e) {  
  29.         // TODO Auto-generated catch block  
  30.         e.printStackTrace();  
  31.     } catch (NoSuchMethodException e) {  
  32.         // TODO Auto-generated catch block  
  33.         e.printStackTrace();  
  34.     }   



判断手机是否为双卡:

  1. public static void initIsDoubleTelephone(Context context){  
  2. boolean isDouble = true;  
  3. Method method = null;  
  4. Object result_0 = null;  
  5. Object result_1 = null;  
  6. TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);  
  7. try {  
  8. //只要在反射getSimStateGemini 这个函数时报了错就是单卡手机(这是我自己的经验,不一定全正确)  
  9. method = TelephonyManager.class.getMethod("getSimStateGemini",new Class[] { int.class });  
  10. //获取SIM卡1  
  11. result_0 = method.invoke(tm, new Object[] { new Integer(0) });  
  12. //获取SIM卡1  
  13. result_1 = method.invoke(tm, new Object[] { new Integer(1) });  
  14. } catch (SecurityException e) {  
  15. isDouble = false;  
  16. e.printStackTrace();  
  17. //System.out.println("1_ISSINGLETELEPHONE:"+e.toString());  
  18. } catch (NoSuchMethodException e) {  
  19. isDouble = false;  
  20. e.printStackTrace();  
  21. //System.out.println("2_ISSINGLETELEPHONE:"+e.toString());  
  22. } catch (IllegalArgumentException e) {  
  23. isDouble = false;  
  24. e.printStackTrace();  
  25. } catch (IllegalAccessException e) {  
  26. isDouble = false;  
  27. e.printStackTrace();  
  28. } catch (InvocationTargetException e) {  
  29. isDouble = false;  
  30. e.printStackTrace();  
  31. } catch (Exception e){  
  32. isDouble = false;  
  33. e.printStackTrace();  
  34. //System.out.println("3_ISSINGLETELEPHONE:"+e.toString());  
  35. }  
  36. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);  
  37. Editor editor = sp.edit();  
  38. if(isDouble){  
  39. //保存为双卡手机  
  40. editor.putBoolean(ISDOUBLE, true);  
  41. //保存双卡是否可用  
  42. //如下判断哪个卡可用.双卡都可以用  
  43. if(result_0.toString().equals("5") && result_1.toString().equals("5")){  
  44. if(!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")){  
  45. editor.putString(SIMCARD, "0");  
  46. }  
  47. editor.putBoolean(SIMCARD_1, true);  
  48. editor.putBoolean(SIMCARD_2, true);  
  49. } else if(!result_0.toString().equals("5") && result_1.toString().equals("5")){//卡二可用  
  50. if(!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")){  
  51. editor.putString(SIMCARD, "1");  
  52. }  
  53. editor.putBoolean(SIMCARD_1, false);  
  54. editor.putBoolean(SIMCARD_2, true);  
  55. } else if(result_0.toString().equals("5") && !result_1.toString().equals("5")){//卡一可用  
  56. if(!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")){  
  57. editor.putString(SIMCARD, "0");  
  58. }  
  59. editor.putBoolean(SIMCARD_1, true);  
  60. editor.putBoolean(SIMCARD_2, false);  
  61. } else {//两个卡都不可用(飞行模式会出现这种种情况)  
  62. editor.putBoolean(SIMCARD_1, false);  
  63. editor.putBoolean(SIMCARD_2, false);  
  64. }  
  65. }else{  
  66. //保存为单卡手机  
  67. editor.putString(SIMCARD, "0");  
  68. editor.putBoolean(ISDOUBLE, false);  
  69. }  
  70. editor.commit();  
  71. }  

android 双卡手机发短信/判断手机是否为双卡,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。