Example usage for android.telephony SubscriptionManager getActiveSubscriptionInfo

List of usage examples for android.telephony SubscriptionManager getActiveSubscriptionInfo

Introduction

In this page you can find the example usage for android.telephony SubscriptionManager getActiveSubscriptionInfo.

Prototype

@SuppressAutoDoc 
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public SubscriptionInfo getActiveSubscriptionInfo(int subId) 

Source Link

Document

Get the active SubscriptionInfo with the input subId.

Usage

From source file:com.master.metehan.filtereagle.Util.java

public static boolean isInternational(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && hasPhoneStatePermission(context)) {
        int dataSubId;
        try {/* w  ww . j  a  v a  2s. c o  m*/
            dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
        } catch (Throwable ignored) {
            dataSubId = -1;
        }
        if (dataSubId >= 0) {
            SubscriptionManager sm = SubscriptionManager.from(context);
            SubscriptionInfo si = sm.getActiveSubscriptionInfo(dataSubId);
            if (si != null && si.getCountryIso() != null)
                try {
                    Method getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription",
                            int.class);
                    getNetworkCountryIso.setAccessible(true);
                    String networkCountryIso = (String) getNetworkCountryIso.invoke(tm, dataSubId);
                    Log.d(TAG, "SIM=" + si.getCountryIso() + " network=" + networkCountryIso);
                    return !si.getCountryIso().equals(networkCountryIso);
                } catch (Throwable ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    sendCrashReport(ex, context);
                }
        }
    }

    return (tm == null || tm.getSimCountryIso() == null
            || !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
}