我无法设置呼叫的默认SIM卡。每次在发送ACTION_CALL意图之前,我都会尝试更改系统设置以更改默认的sim,但每次我都会看到sim选择对话框
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;
}}
我的意图是使用Android5.1API通过特定的SIM卡发出呼叫。如果有其他方法,请告诉我。
发布于 2019-10-03 04:03:25
在API级别22及以上,我们可以在使用SubscriptionManager和TelecomManager进行调用意图时设置sim选择,如下所示。
//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 22和更高版本,并需要READ_PHONE_STATE权限
发布于 2016-01-19 17:31:51
双卡并不是Android SDK的官方支持。我建议你捕获logcat并使用系统拨号器进行特定的sim呼叫,找出关于sim卡的意图格式。
更新
从api的22级来看,sdk支持双卡link,但我在SDK文档中找不到双卡的ACTION_CALL intent格式。
发布于 2017-07-22 22:05:29
True-caller app已经能够添加一个按钮,用于选择特定的SIM卡来发送或接收语音和文本消息。我尝试过5.1中引入的SubscriptionManager应用程序接口,但仍然没有得到任何更改。
https://stackoverflow.com/questions/33451660
复制相似问题