android设置默认的sim卡

Android 4.4

ConnectivityManager mConnService;
TelephonyManager.setDefaultDataPhoneId(context, phoneId);
mConnService.setMobileDataEnabledByPhoneId(phoneId, true);

Android 7之后

private static void setDefaultDataSubId(Context context, int subId) {
       SubscriptionManager.from(context).setDefaultDataSubId(subId);
}


SubscriptionManager.from(context).setDefaultSmsSubId(subId);



SubscriptionManager.getDefaultDataSubscriptionId()



mSubscriptionManager.addOnSubscriptionsChangedListener(this.mOnSubscriptionsChangeListener);



https://android.googlesource.com/platform/frameworks/base/+/master/telephony/java/android/telephony/SubscriptionManager.java

/**
     * Set the subscription which will be used by default for data, with the subscription which
     * the supplied subscription ID corresponds to; or throw a RuntimeException if the supplied
     * subscription ID is not usable (check with {@link #isUsableSubscriptionId(int)}).
     *
     * @param subscriptionId the supplied subscription ID
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    public void setDefaultDataSubId(int subscriptionId) {
        if (VDBG) logd("setDataSubscription sub id = " + subscriptionId);
        try {
            ISub iSub = TelephonyManager.getSubscriptionService();
            if (iSub != null) {
                iSub.setDefaultDataSubId(subscriptionId);
            }
        } catch (RemoteException ex) {
            // ignore it
        }
    }

小米
miui.telephony.SubscriptionManager
SubscriptionManager.getDefault().setDefaultDataSlotId(slot_id);

摩托
com.motorola.msimsettings.utils.SmartSimUtils

    public static int setSimForDataWithStatusToast(Context context, int arg3) {
        int result = SmartSimUtils.setSimForData(context, arg3);
        Toast.makeText(context, SmartSimUtils.mapDDSSwitchStatusToMessageResId(result), 1).show();  // 切换可能需要1分钟
        SmartSimUtils.notifyDdsAssistantSlotChanged(context);
        return result;
    }


    public int setDefaultDataSubIdWithNwAutoSwitch(int arg1) {
        return this.mManager.setDefaultDataSubIdWithNwAutoSwitch(arg1);
    }


    public MotoExtTelephonyManagerAdapter(Context arg2) {
        this.mManager = new MotoExtTelephonyManager(arg2);
    }

com.motorola.android.telephony.MotoExtTelephonyManager

    private IMotoExtTelephony getIMotoExtTelephony() {
        return com.motorola.android.internal.telephony.IMotoExtTelephony.Stub.asInterface(ServiceManager.getService("motoexttelephony"));
    }

    public int setDefaultDataSubIdWithNwAutoSwitch(int ddsSubId) {
        try {
            IMotoExtTelephony motoExtTelephony = this.getIMotoExtTelephony();
            if(motoExtTelephony == null) {
                this.loge("moto ext telephony is null");
                return -1;
            }

            return motoExtTelephony.setDefaultDataSubIdWithNwAutoSwitch(ddsSubId);
        }
        catch(RemoteException | NullPointerException ex) {
            return -1;
        }
    }




发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注