//判断手机上有几个SIM卡 @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1) public static int getAvailableSimCardCount(Context context){ int count = 0; SubscriptionManager mSubscriptionManager = SubscriptionManager.from(context); for(int i = 0; i < getSimCardCount(context); i++){ SubscriptionInfo sir = mSubscriptionManager .getActiveSubscriptionInfoForSimSlotIndex(i); if(sir != null){ count++; } } return count; } //判断手机上有几个SIM卡 public static int getSimCardCount(Context context) { TelephonyManager mTelephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); Class cls = mTelephonyManager.getClass(); try { Method mMethod = cls.getMethod("getSimCount"); mMethod.setAccessible(true); return (int) mMethod.invoke(mTelephonyManager); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return -1; }
//指定SIM卡拨打 public static final String[] dualSimTypes = { "subscription", "Subscription", "com.android.phone.extra.slot", "phone", "com.android.phone.DialingMode", "simId", "simnum", "phone_type", "simSlot" }; private void call(String phone) { Intent callIntent = new Intent(Intent.ACTION_CALL) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); callIntent.setData(Uri.parse("tel:" + phone)); for (int i=0; i < dualSimTypes.length; i++) { callIntent.putExtra(dualSimTypes[i], 2); } this.startActivity(callIntent); }