當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。