Java Code Examples for android.telephony.SubscriptionManager#from()

The following examples show how to use android.telephony.SubscriptionManager#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsFragment.java    From sms-ticket with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void fillDualSimList(PreferenceScreen preferenceScreen) {
    PreferenceCategory category = (PreferenceCategory) preferenceScreen.findPreference("sms_category");
    ListPreference preference = (ListPreference) category.findPreference(Preferences.DUALSIM_SIM);
    List<String> simIds = new ArrayList<>();
    List<String> simNames = new ArrayList<>();
    simIds.add(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    simNames.add(getString(R.string.sim_default));
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    for (SubscriptionInfo subscriptionInfo : subscriptionManager.getActiveSubscriptionInfoList()) {
        simIds.add(String.valueOf(subscriptionInfo.getSubscriptionId()));
        simNames.add(getString(R.string.sim_name, subscriptionInfo.getSimSlotIndex() + 1, subscriptionInfo
            .getDisplayName()));
    }
    preference.setEntries(simNames.toArray(new String[simNames.size()]));
    preference.setEntryValues(simIds.toArray(new String[simIds.size()]));
    preference.setDefaultValue(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    preference.setSummary(preference.getEntry());
}
 
Example 2
Source File: SimChangedReceiver.java    From Silence with GNU General Public License v3.0 7 votes vote down vote up
private static String getDeviceSubscriptions(Context context) {
  if (Build.VERSION.SDK_INT < 22) return "1";

  SubscriptionManager    subscriptionManager = SubscriptionManager.from(context);
  List<SubscriptionInfo> activeSubscriptions = subscriptionManager.getActiveSubscriptionInfoList();

  if (activeSubscriptions == null) return "1";

  String[] subscriptions = new String[activeSubscriptions.size()];
  for(int i=0; i<activeSubscriptions.size(); i++){
    subscriptions[i] = Integer.toString(activeSubscriptions.get(i).getSubscriptionId());
  }

  Arrays.sort(subscriptions);

  return joinString(subscriptions);
}
 
Example 3
Source File: EmergencyAffordanceService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onBootPhase(int phase) {
    if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
        mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
        mVoiceCapable = mTelephonyManager.isVoiceCapable();
        if (!mVoiceCapable) {
            updateEmergencyAffordanceNeeded();
            return;
        }
        mSubscriptionManager = SubscriptionManager.from(mContext);
        HandlerThread thread = new HandlerThread(TAG);
        thread.start();
        mHandler = new MyHandler(thread.getLooper());
        mHandler.obtainMessage(INITIALIZE_STATE).sendToTarget();
        startScanning();
        IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        mContext.registerReceiver(mAirplaneModeReceiver, filter);
        mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionChangedListener);
    }
}
 
Example 4
Source File: SimCardUtils.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
@SuppressLint({"NewApi"})
private void getDefaultSub(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager subscriptionManager = SubscriptionManager.from(context.getApplicationContext());
        if (subscriptionManager != null) {
            try {
                SubscriptionInfo subscriptionInfo = this.getSubInfo(subscriptionManager, "getDefaultDataSubscriptionInfo", (Object[]) null);
                if (subscriptionInfo != null) {
                    this.mSimCardInfo.simSub = subscriptionInfo.getSimSlotIndex();
                }
            } catch (Exception e) {
                Log.i(TAG, e.toString());
            }
        }
    } else {
        this.mSimCardInfo.simSub = -1;
    }

}
 
Example 5
Source File: SimCardUtils.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
@SuppressLint({"NewApi"})
private List<SubscriptionInfo> getSubInfoList(Context context) {
    SubscriptionManager subscriptionManager = SubscriptionManager.from(context.getApplicationContext());
    List list = null;
    if (subscriptionManager != null) {
        list = subscriptionManager.getActiveSubscriptionInfoList();
    }

    return list;
}
 
Example 6
Source File: SubscriptionHelper.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Nullable
public static List<SubscriptionInfo> getSubscriptions(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(context);
        return sm.getActiveSubscriptionInfoList();
    }

    return null;
}
 
Example 7
Source File: Phone.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves network operator names from subscription manager.
 * NOTE: Requires SDK level 22 or above
 *
 * @param context
 * @return
 */
private static String getNetworkOperators(Context context) {
    String operator = "";

    if (!PermissionsUtils.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
        return operator;
    }

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
        if (subscriptionManager != null) {
            List<SubscriptionInfo> subscriptions =
                    subscriptionManager.getActiveSubscriptionInfoList();
            if (subscriptions != null) {
                for (SubscriptionInfo info : subscriptions) {
                    CharSequence carrierName = info.getCarrierName();
                    if (carrierName != null && carrierName.length() > 0) {
                        operator += carrierName + ";";
                    }
                }
                // Remove last delimiter
                if (operator.length() >= 1) {
                    operator = operator.substring(0, operator.length() - 1);
                }
            }
        }
    }
    return operator;
}
 
Example 8
Source File: DualSimNewApiWrapper.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
public boolean isDualSim(final Context context)
{
    try
    {
        final SubscriptionManager sm = SubscriptionManager.from(context);
        final int activeSubscriptionInfoCount = sm.getActiveSubscriptionInfoCount();
        //System.out.println("active subscription count: " + activeSubscriptionInfoCount);
        return activeSubscriptionInfoCount > 1;
    }
    catch (Throwable t)
    {
        //t.printStackTrace();
        return false;
    }
}
 
Example 9
Source File: Util.java    From kcanotify with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    if (!hasPhoneStatePermission(context))
        return "No permission";

    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);

    sb.append("Slots ")
            .append(sm.getActiveSubscriptionInfoCount())
            .append('/')
            .append(sm.getActiveSubscriptionInfoCountMax())
            .append("\r\n");

    int dataid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        dataid = sm.getDefaultDataSubscriptionId();

    int voiceid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        voiceid = sm.getDefaultVoiceSubscriptionId();

    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null)
        for (SubscriptionInfo si : subscriptions)
            sb.append("SIM ")
                    .append(si.getSimSlotIndex() + 1)
                    .append('/')
                    .append(si.getSubscriptionId())
                    .append(' ')
                    .append(si.getCountryIso())
                    .append('/')
                    .append(si.getMcc()).append(si.getMnc())
                    .append(' ')
                    .append(si.getCarrierName())
                    .append(si.getSubscriptionId() == dataid ? " D" : "")
                    .append(si.getSubscriptionId() == voiceid ? " V" : "")
                    .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append("\r\n");

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}