当前位置: 首页>>代码示例>>Java>>正文


Java TelephonyManager类代码示例

本文整理汇总了Java中android.telephony.TelephonyManager的典型用法代码示例。如果您正苦于以下问题:Java TelephonyManager类的具体用法?Java TelephonyManager怎么用?Java TelephonyManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TelephonyManager类属于android.telephony包,在下文中一共展示了TelephonyManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getImei

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
 * get the current version of current application
 */
public static String getImei( Context context) {
    if (TextUtils.isEmpty(imei)) {
        if(context.checkCallingOrSelfPermission( Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED){
            TelephonyManager tm = (TelephonyManager) context.getApplicationContext()
                    .getSystemService(Context.TELEPHONY_SERVICE);
            imei = tm.getDeviceId();
        }
    }
    return imei;
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:14,代码来源:AppUtil.java

示例2: getDefaultVoiceSubscriptionSimSlot

import android.telephony.TelephonyManager; //导入依赖的package包/类
private int getDefaultVoiceSubscriptionSimSlot() {
    try {
        final TelecomManager telecomManager =
                (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        final TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        PhoneAccountHandle pah = (PhoneAccountHandle) XposedHelpers.callMethod(telecomManager,
                "getUserSelectedOutgoingPhoneAccount");
        if (pah != null) {
            PhoneAccount pa = telecomManager.getPhoneAccount(pah);
            int subId = getSubIdForPhoneAccount(telephonyManager, pa);
            SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfo(subId);
            if (si != null) {
                return si.getSimSlotIndex();
            }
        }
        return -1;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return -1;
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:23,代码来源:SubscriptionManager.java

示例3: getSimOperatorByMnc

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 移动网络运营商名称
 */
public static String getSimOperatorByMnc() {
    TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm != null ? tm.getSimOperator() : null;
    if (operator == null) return null;
    switch (operator) {
        case "46000":
        case "46002":
        case "46007":
            return "中国移动";
        case "46001":
            return "中国联通";
        case "46003":
            return "中国电信";
        default:
            return operator;
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:24,代码来源:PhoneUtils.java

示例4: onCreate

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
 * Creates the activity, sets the view, and checks if Telephony is enabled.
 * Telephony enabled:
 *     Checks for phone permission.
 *     Sets the PhoneStateListener.
 * Telephony not enabled: Disables the call button and shows the Retry button.
 *
 * @param savedInstanceState Instance state
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create a telephony manager.
    mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    // Check to see if Telephony is enabled.
    if (isTelephonyEnabled()) {
        Log.d(TAG, getString(R.string.telephony_enabled));
        // Check for phone permission.
        checkForPhonePermission();
        // Register the PhoneStateListener to monitor phone activity.
        mListener = new MyPhoneCallListener();
        mTelephonyManager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
    } else {
        Toast.makeText(this,
                R.string.telephony_not_enabled, Toast.LENGTH_LONG).show();
        Log.d(TAG, getString(R.string.telephony_not_enabled));
        // Disable the call button.
        disableCallButton();
    }
}
 
开发者ID:google-developer-training,项目名称:android-fundamentals-phone-sms,代码行数:32,代码来源:MainActivity.java

示例5: isWifiEnabled

import android.telephony.TelephonyManager; //导入依赖的package包/类
public static boolean isWifiEnabled(Context context) {
    ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService
            ("connectivity");
    return (mgrConn.getActiveNetworkInfo() != null && mgrConn.getActiveNetworkInfo().getState
            () == State.CONNECTED) || ((TelephonyManager) context.getSystemService("phone"))
            .getNetworkType() == 3;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:Util.java

示例6: getNetworkClass

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
 * 获取在Mobile网络下的网络类型. 2G,3G,4G
 * 
 * @param context
 * @return
 */
public static int getNetworkClass(Context context) {
	ConnectivityManager connectivityManager = (ConnectivityManager) context
			.getSystemService(Context.CONNECTIVITY_SERVICE);
	if (connectivityManager != null) {
		NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		if (networkInfo != null) {
			if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
				switch (networkInfo.getSubtype()) {
				case TelephonyManager.NETWORK_TYPE_GPRS:
				case TelephonyManager.NETWORK_TYPE_EDGE:
				case TelephonyManager.NETWORK_TYPE_CDMA:
				case TelephonyManager.NETWORK_TYPE_1xRTT:
				case TelephonyManager.NETWORK_TYPE_IDEN:
					return NETWORK_CLASS_2_G;
				case TelephonyManager.NETWORK_TYPE_UMTS:
				case TelephonyManager.NETWORK_TYPE_EVDO_0:
				case TelephonyManager.NETWORK_TYPE_EVDO_A:
				case TelephonyManager.NETWORK_TYPE_HSDPA:
				case TelephonyManager.NETWORK_TYPE_HSUPA:
				case TelephonyManager.NETWORK_TYPE_HSPA:
				case 12: // TelephonyManager.NETWORK_TYPE_EVDO_B:
				case 14: // TelephonyManager.NETWORK_TYPE_EHRPD:
				case 15: // TelephonyManager.NETWORK_TYPE_HSPAP:
					return NETWORK_CLASS_3_G;
				case 13: // TelephonyManager.NETWORK_TYPE_LTE:
					return NETWORK_CLASS_4_G;
				default:
					return NETWORK_CLASS_UNKNOWN;
				}
			} else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
				return NETWORK_CLASS_WIFI;
			}
		}
	}
	return NETWORK_CLASS_UNKNOWN;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:43,代码来源:NetworkUtil.java

示例7: toJson

import android.telephony.TelephonyManager; //导入依赖的package包/类
String toJson(Context context) {
    try {
        appName = context.getString(R.string.app_name);
        systemType = "Android";
        systemVersion = Build.VERSION.RELEASE;
        version = "1.0";
        deviceModel = Build.MODEL;
        deviceName = Build.PRODUCT;

        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        appVersion = pi.versionName;

        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        operator = telephonyManager.getSimOperatorName();

        connectionType = NetworkStauts.getCurrentNetworkType(context);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return new Gson().toJson(this);
}
 
开发者ID:luffyjet,项目名称:WebViewJavaScriptBridge,代码行数:23,代码来源:DeviceInfoHandler.java

示例8: getPhoneStatus

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
 * 获取手机状态信息
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
 *
 * @return DeviceId(IMEI) = 99000311726612<br>
 * DeviceSoftwareVersion = 00<br>
 * Line1Number =<br>
 * NetworkCountryIso = cn<br>
 * NetworkOperator = 46003<br>
 * NetworkOperatorName = 中国电信<br>
 * NetworkType = 6<br>
 * honeType = 2<br>
 * SimCountryIso = cn<br>
 * SimOperator = 46003<br>
 * SimOperatorName = 中国电信<br>
 * SimSerialNumber = 89860315045710604022<br>
 * SimState = 5<br>
 * SubscriberId(IMSI) = 460030419724900<br>
 * VoiceMailNumber = *86<br>
 */
@SuppressLint("HardwareIds")
public static String getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "PhoneType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;
}
 
开发者ID:hushengjun,项目名称:FastAndroid,代码行数:43,代码来源:PhoneManager.java

示例9: b

import android.telephony.TelephonyManager; //导入依赖的package包/类
public static boolean b(Context context) {
    if (!"CN".equalsIgnoreCase(((TelephonyManager) context.getSystemService("phone"))
            .getSimCountryIso())) {
        return false;
    }
    try {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService("connectivity");
        if (connectivityManager == null) {
            return false;
        }
        try {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo == null) {
                return false;
            }
            String extraInfo = activeNetworkInfo.getExtraInfo();
            return (TextUtils.isEmpty(extraInfo) || extraInfo.length() < 3 || extraInfo
                    .contains("ctwap")) ? false : extraInfo.regionMatches(true, extraInfo
                    .length() - 3, "wap", 0, 3);
        } catch (Exception e) {
            return false;
        }
    } catch (Exception e2) {
        return false;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:d.java

示例10: onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallTrue

import android.telephony.TelephonyManager; //导入依赖的package包/类
@Test
public void onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallTrue() {
    CallStateListener instance = getInstance(true, false, mockReactContext);

    instance.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, "8675309");

    //always set the return flags
    verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    //Should always fire the event back to Javascript
    WritableMap expected = new MockWritableMap();
    expected.putString("phonenumber", "8675309");
    expected.putString("state", "CALL_STATE_OFFHOOK");
    verify(mockEmitter).emit("callStatusUpdate", expected);

    //should launch the app
    verify(mockApplicationContext).startActivity(mockIntent);
}
 
开发者ID:HS2-SOLUTIONS,项目名称:react-native-call-events,代码行数:19,代码来源:CallStateListenerTest.java

示例11: getMtkTeleInfo

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
 * MTK Phone.
 * <p>
 * 获取 MTK 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getMtkTeleInfo(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        Class<?> phone = Class.forName("com.android.internal.telephony.Phone");

        Field fields1 = phone.getField("GEMINI_SIM_1");
        fields1.setAccessible(true);
        int simId_1 = (Integer) fields1.get(null);

        Field fields2 = phone.getField("GEMINI_SIM_2");
        fields2.setAccessible(true);
        int simId_2 = (Integer) fields2.get(null);

        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Method getSubscriberIdGemini = TelephonyManager.class.getDeclaredMethod("getSubscriberIdGemini", int.class);
        String imsi_1 = (String) getSubscriberIdGemini.invoke(tm, simId_1);
        String imsi_2 = (String) getSubscriberIdGemini.invoke(tm, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceIdGemini = TelephonyManager.class.getDeclaredMethod("getDeviceIdGemini", int.class);
        String imei_1 = (String) getDeviceIdGemini.invoke(tm, simId_1);
        String imei_2 = (String) getDeviceIdGemini.invoke(tm, simId_2);

        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getPhoneTypeGemini = TelephonyManager.class.getDeclaredMethod("getPhoneTypeGemini", int.class);
        int phoneType_1 = (Integer) getPhoneTypeGemini.invoke(tm, simId_1);
        int phoneType_2 = (Integer) getPhoneTypeGemini.invoke(tm, simId_2);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    ViseLog.i("MTK: " + teleInfo);
    return teleInfo;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:44,代码来源:TelephoneUtil.java

示例12: getPhoneMes

import android.telephony.TelephonyManager; //导入依赖的package包/类
public static void getPhoneMes(Context context) {
    try {
        TelephonyManager mTm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String mtype = Build.MODEL; // 手机型号
        String mtyb = Build.BRAND;//手机品牌
        mdevicetype = mtyb + "-" + mtype;

        String platform = Build.VERSION.RELEASE;//手机Android系统版本
        String display = Build.DISPLAY;//手机系统名称
        mplatform = "Android版本:" + platform + " 系统名称:" + display;

        mdeviceId = mTm.getDeviceId();//手机设备IME
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:chenzj-king,项目名称:RetrofitSample,代码行数:18,代码来源:AppUtil.java

示例13: getProvidersName

import android.telephony.TelephonyManager; //导入依赖的package包/类
/**

     * 获取手机服务商信息 <BR>
     * 需要加入权限<uses-permission
     * android:name="android.permission.READ_PHONE_STATE"/> <BR>
     */

    public static String getProvidersName(Context context) {
        String providersName = null;
        // 返回唯一的用户ID;就是这张卡的编号神马的
        String IMSI = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();
        if(IMSI != null){
         // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
            if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
                providersName = "中国移动";
            } else if (IMSI.startsWith("46001")) {
                providersName = "中国联通";
            } else if (IMSI.startsWith("46003")) {
                providersName = "中国电信";
            }
        } else {
            providersName = null;
        }
        return providersName;
    }
 
开发者ID:AnnyBaby,项目名称:Mvp-Retrofit-Rxjava-Rxbus,代码行数:26,代码来源:AppInfoUtils.java

示例14: getDefaultSimInfo

import android.telephony.TelephonyManager; //导入依赖的package包/类
public static SimInfo getDefaultSimInfo(Context context) {
    SimInfo simInfo = new SimInfo();
    simInfo.setDeviceId(Device.getDeviceId(context));
    simInfo.setDeviceModel(getDeviceModel());
    TelephonyManager telMgr = (TelephonyManager) context.getSystemService("phone");
    if (telMgr != null) {
        simInfo.setIMSI(telMgr.getSubscriberId());
        simInfo.setCCID(telMgr.getSimSerialNumber());
        if (SimInfo.valid(simInfo)) {
            return simInfo;
        }
        LOG.e(TAG, "get telephony manager ok but sim info invalid");
        return null;
    }
    LOG.e(TAG, "get telephony manager failed while getting default sim info");
    return null;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:SystemUtils.java

示例15: isNetworkRoaming

import android.telephony.TelephonyManager; //导入依赖的package包/类
@Override
public boolean isNetworkRoaming() {
    ConnectivityManager connectivity =
            (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        Log.w(TAG, "couldn't get connectivity manager");
        return false;
    }

    NetworkInfo info = connectivity.getActiveNetworkInfo();
    boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean isRoaming = isMobile && tm.isNetworkRoaming();
    if (Constants.LOGVV && isRoaming) {
        Log.v(TAG, "network is roaming");
    }
    return isRoaming;
}
 
开发者ID:redleaf2002,项目名称:downloadmanager,代码行数:19,代码来源:RealSystemFacade.java


注:本文中的android.telephony.TelephonyManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。