Which sim is using mobile data..?

371 Views Asked by At

How to check which sim is using mobile data? or put it this way; mobile data is enabled on which sim?

1

There are 1 best solutions below

0
On BEST ANSWER

after a struggling a lot, i was able to find that which sim is using mobile data, but this code only works on android version 7 and above. this code will check, if data is enabled on primary sim, return true, else return false.

private boolean checkIsValidPrimarySim(Context context) {
    boolean validSim=false;
    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
        int mSubscriptionId=-1;
        SubscriptionManager subscriptionManager=(SubscriptionManager)context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        SubscriptionInfo subscriptionInfo=subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(0);
        if(subscriptionInfo!=null){
            mSubscriptionId=subscriptionInfo.getSubscriptionId();
            if(mSubscriptionId!=-1){
                int defaultSubscriptionId=subscriptionManager.getDefaultDataSubscriptionId();
                if(mSubscriptionId==defaultSubscriptionId){
                    validSim=true;
                }
                else {
                    //display message to change your defalult data sim


                }
            }else {
                //display message to change your defalult data sim
            }

        }
        else {
         //display message to change your defalult data sim
        }

    }
    return validSim;
}