首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -如何在双卡手机中通过特定的SIM卡拨打电话?

Android -如何在双卡手机中通过特定的SIM卡拨打电话?
EN

Stack Overflow用户
提问于 2015-10-31 20:37:47
回答 3查看 2K关注 0票数 4

我无法设置呼叫的默认SIM卡。每次在发送ACTION_CALL意图之前,我都会尝试更改系统设置以更改默认的sim,但每次我都会看到sim选择对话框

代码语言:javascript
复制
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卡发出呼叫。如果有其他方法,请告诉我。

EN

回答 3

Stack Overflow用户

发布于 2019-10-03 04:03:25

在API级别22及以上,我们可以在使用SubscriptionManager和TelecomManager进行调用意图时设置sim选择,如下所示。

代码语言:javascript
复制
    //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权限

票数 5
EN

Stack Overflow用户

发布于 2016-01-19 17:31:51

双卡并不是Android SDK的官方支持。我建议你捕获logcat并使用系统拨号器进行特定的sim呼叫,找出关于sim卡的意图格式。

更新

从api的22级来看,sdk支持双卡link,但我在SDK文档中找不到双卡的ACTION_CALL intent格式。

票数 0
EN

Stack Overflow用户

发布于 2017-07-22 22:05:29

True-caller app已经能够添加一个按钮,用于选择特定的SIM卡来发送或接收语音和文本消息。我尝试过5.1中引入的SubscriptionManager应用程序接口,但仍然没有得到任何更改。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33451660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档