我无法设置默认的SIM卡进行调用。我试图改变系统设置,以便在我发送ACTION_CALL意图之前每次更改默认模拟器,但是我正在获取模拟选择对话框
public class CallUtil {
public static void sendCallIntent(Context context, String number) {
Intent intent = new Intent(Intent.ACTION_CALL)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + number));
setDefaultSim(context);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
context.startActivity(intent);
}
public static void setDefaultSim(Context context) {
try {
ContentValues val = new ContentValues();
List<Integer> sims = getInsertedSIMIds(context);
val.put("value", sims.get(0));
context.getContentResolver().update(Uri.parse("content://settings/system"), val, "name='voice_call_sim_setting'", null);
} catch (Exception e) {
}
}
public static List<Integer> getInsertedSIMIds(Context context){
List<Integer> list = new ArrayList<Integer>();
SubscriptionManager sm=(SubscriptionManager)context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
for ( SubscriptionInfo sub: sm.getActiveSubscriptionInfoList()) {
list.add(sub.getSimSlotIndex());
}
return list;
}
}
我的目的是使用Android 5.1 API通过特定的SIM卡发出呼叫。如果有其他方法,请告诉我。
答案 0 :(得分:1)
从API级别22开始,我们可以使用SubscriptionManager和TelecomManager进行呼叫意图的设置,如下所示。
//To find SIM ID
String primarySimId,secondarySimId;
SubscriptionManager subscriptionManager = (SubscriptionManager) appContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subList = subscriptionManager.getActiveSubscriptionInfoList();
int index=-1;
for (SubscriptionInfo subscriptionInfo : subList) {
index++;
if(index == 0){
primarySimId=subscriptionInfo.getIccId();
}else {
secondarySimId=subscriptionInfo.getIccId();
}
}
// TO CREATE PhoneAccountHandle FROM SIM ID
TelecomManager telecomManager =(TelecomManager) getSystemService(Context.TELECOM_SERVICE);
List<PhoneAccountHandle> list = telecomManager.getCallCapablePhoneAccounts();
PhoneAccountHandle primaryPhoneAccountHandle,secondaryPhoneAccountHandle;
for(PhoneAccountHandle phoneAccountHandle:list){
if(phoneAccountHandle.getId().contains(primarySimId)){
primaryPhoneAccountHandle=phoneAccountHandle;
}
if(phoneAccountHandle.getId().contains(secondarySimId)){
secondaryPhoneAccountHandle=phoneAccountHandle;
}
}
//To call from SIM 1
Uri uri = Uri.fromParts("tel",number, "");
Bundle extras = new Bundle(); extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,primaryPhoneAccountHandle);
telecomManager.placeCall(uri, extras);
//To call from SIM 2
Uri uri = Uri.fromParts("tel",number, "");
Bundle extras = new Bundle(); extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,secondaryPhoneAccountHandle);
telecomManager.placeCall(uri, extras);
有关更多详细信息,请参见https://developer.android.com/reference/android/telephony/SubscriptionManager.html 同样,以上代码仅适用于API 22及更高版本,并且需要READ_PHONE_STATE权限
答案 1 :(得分:0)
双SIM卡不是Android SDK的官方支持。我建议你捕获logcat并使用系统拨号器进行特定的sim调用,找出有关sim卡的意图格式。
<强>更新强>
来自api level 22,sdk支持双sim link,但我找不到SDK文档中双sim卡的ACTION_CALL意图格式。
答案 2 :(得分:0)
真正的来电应用已经能够添加一个按钮,用于选择指定的SIM卡来发送或接收语音和短信。 尝试过在5.1中引入的SubscriptionManager API,但仍然没有变化。