栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android指定sim卡拨打电话

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android指定sim卡拨打电话

1:申请权限

Manifest.permission.CALL_PHONE

2:创建intent
 Intent intent = new Intent(Intent.ACTION_CALL);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3:获取 PhoneAccountHandle

above android.os.Build.VERSION_CODES.M 以上添加 PhoneAccountHandle。

  
    public static PhoneAccountHandle getPhoneAccountHandle(String iccid) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
            return null;
        }
        try {
            TelecomManager telecomManager = (TelecomManager) AppEnv.getContext().getSystemService(TELECOM_SERVICE);
            if (telecomManager == null) {
                return null;
            }
            List phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
            if (phoneAccountHandleList == null || phoneAccountHandleList.isEmpty()) {
                return null;
            }
            for (PhoneAccountHandle handle : phoneAccountHandleList) {
                if (iccid.equalsIgnoreCase(handle.getId())) {
                    return handle;
                }
            }
        } catch (Throwable e) {
            Log.e(TAG, "getPhoneAccountHandle error:", e);
        }
        return null;
    }
		PhoneAccountHandle phoneAccountHandle = null;
        if (!TextUtils.isEmpty(iccId) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            phoneAccountHandle =getPhoneAccountHandle(iccId);
            if (phoneAccountHandle != null) {
                intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
            }
        }
4:添加soltId

PhoneAccountHandle==null 或者低于m .

 public static final String[] dualSimTypes = {
            "extra_asus_dial_use_dualsim",
            "com.android.phone.extra.slot",//基本上是这个
            "slot",
            "simslot",
            "sim_slot",
            "subscription",//华为是这个
            "Subscription",
            "phone",
            "com.android.phone.DialingMode",
            "simSlot",
            "slot_id",//小米是这个
            "simId",
            "simnum",
            "phone_type",
            "slotId",
            "slotIdx"
    };
 for (String dualSimType : dualSimTypes) {
                    //所有的可能都加上
                    intent.putExtra(dualSimType, slotId);
                }
5:拨打电话
      Uri data = Uri.parse("tel:" + phone);
            intent.setData(data);
            try {
                context.startActivity(intent);
                return true;
            } catch (Throwable e) {
               Log.e(TAG, "startCall error: ", e);
            }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1021300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号