Example usage for android.telephony TelephonyManager getClass

List of usage examples for android.telephony TelephonyManager getClass

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

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

@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);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

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

    int dataSubId;
    try {//from w ww  .jav  a  2  s. c  o  m
        dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
    } catch (Throwable ignored) {
        dataSubId = -1;
    }

    Method getNetworkCountryIso = null;
    Method getNetworkOperator = null;
    Method getNetworkOperatorName = null;
    Method getDataEnabled = null;
    try {
        getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription", int.class);
        getNetworkOperator = tm.getClass().getMethod("getNetworkOperatorForSubscription", int.class);
        getNetworkOperatorName = tm.getClass().getMethod("getNetworkOperatorName", int.class);
        getDataEnabled = tm.getClass().getMethod("getDataEnabled", int.class);

        getNetworkCountryIso.setAccessible(true);
        getNetworkOperator.setAccessible(true);
        getNetworkOperatorName.setAccessible(true);
        getDataEnabled.setAccessible(true);
    } catch (NoSuchMethodException ex) {
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    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.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append(si.getSubscriptionId() == dataSubId ? " *" : "").append("\r\n");
            if (getNetworkCountryIso != null && getNetworkOperator != null && getNetworkOperatorName != null
                    && getDataEnabled != null)
                try {
                    sb.append("Network ").append(si.getSimSlotIndex() + 1).append('/')
                            .append(si.getSubscriptionId()).append(' ')
                            .append(getNetworkCountryIso.invoke(tm, si.getSubscriptionId())).append('/')
                            .append(getNetworkOperator.invoke(tm, si.getSubscriptionId())).append(' ')
                            .append(getNetworkOperatorName.invoke(tm, si.getSubscriptionId()))
                            .append(sm.isNetworkRoaming(si.getSubscriptionId()) ? " R" : "").append(' ')
                            .append(String.format("%B", getDataEnabled.invoke(tm, si.getSubscriptionId())))
                            .append("\r\n");
                } catch (IllegalAccessException | InvocationTargetException ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }

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

    return sb.toString();
}

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 {/*from www .jav  a 2 s  . 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()));
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

@SuppressWarnings("unchecked")
public static void endIncomingCall() {
    if (!hasCallPermissions) {
        return;/*  w  w  w. java  2s.c o m*/
    }
    try {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext
                .getSystemService(Context.TELEPHONY_SERVICE);
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        ITelephony telephonyService = (ITelephony) m.invoke(tm);
        telephonyService = (ITelephony) m.invoke(tm);
        telephonyService.silenceRinger();
        telephonyService.endCall();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}