java类android.telephony.TelephonyManager的实例源码

AppUtil.java 文件源码 项目:ViewDebugHelper 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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;
}
PhoneUtils.java 文件源码 项目:RLibrary 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 获取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;
    }
}
MainActivity.java 文件源码 项目:android-fundamentals-phone-sms 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
Util.java 文件源码 项目:boohee_v5.6 阅读 28 收藏 0 点赞 0 评论 0
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;
}
SubscriptionManager.java 文件源码 项目:GravityBox 阅读 23 收藏 0 点赞 0 评论 0
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;
    }
}
NetworkUtil.java 文件源码 项目:decoy 阅读 34 收藏 0 点赞 0 评论 0
/**
 * 获取在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;
}
DeviceInfoHandler.java 文件源码 项目:WebViewJavaScriptBridge 阅读 18 收藏 0 点赞 0 评论 0
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);
}
PhoneManager.java 文件源码 项目:FastAndroid 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 获取手机状态信息
 * <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;
}
d.java 文件源码 项目:boohee_v5.6 阅读 34 收藏 0 点赞 0 评论 0
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;
    }
}
CallStateListenerTest.java 文件源码 项目:react-native-call-events 阅读 22 收藏 0 点赞 0 评论 0
@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);
}
TelephoneUtil.java 文件源码 项目:AndroidBasicLibs 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
MainActivity.java 文件源码 项目:android-fundamentals-phone-sms 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
AppUtil.java 文件源码 项目:RetrofitSample 阅读 38 收藏 0 点赞 0 评论 0
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();
    }
}
AppInfoUtils.java 文件源码 项目:Mvp-Retrofit-Rxjava-Rxbus 阅读 21 收藏 0 点赞 0 评论 0
/**

     * 获取手机服务商信息 <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;
    }
SystemUtils.java 文件源码 项目:letv 阅读 32 收藏 0 点赞 0 评论 0
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;
}
RealSystemFacade.java 文件源码 项目:downloadmanager 阅读 31 收藏 0 点赞 0 评论 0
@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;
}
Utils.java 文件源码 项目:MovieApp 阅读 22 收藏 0 点赞 0 评论 0
public static String getUserCountry(Context context) {
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        final String simCountry = tm.getSimCountryIso();
        if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
            Timber.i(simCountry);
            return simCountry.toLowerCase(Locale.US);
        } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
            String networkCountry = tm.getNetworkCountryIso();
            if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
                return networkCountry.toLowerCase(Locale.US);
            }
        }
    } catch (Exception e) {
        Timber.i(e.getMessage());
    }
    return null;
}
CallStateListenerTest.java 文件源码 项目:react-native-call-events 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallFalse() {
    CallStateListener instance = getInstance(false, true, 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 not attempt to launch the app
    verify(mockApplicationContext, never()).startActivity(any(Intent.class));
}
NetworkUtil.java 文件源码 项目:RLibrary 阅读 31 收藏 0 点赞 0 评论 0
public static String getSimOperator(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        return tm.getSimOperator();
    }
    return null;
}
MapViewerOsmDroid.java 文件源码 项目:AIMSICDL 阅读 19 收藏 0 点赞 0 评论 0
@Override
protected void onDestroy() {
    super.onDestroy();
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    // Unbind from the service
    if (mBound) {
        unbindService(mConnection);
        mBound = false;
    }

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}
HttpHead.java 文件源码 项目:ClouldReader 阅读 24 收藏 0 点赞 0 评论 0
private static String getUuid() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String tmDevice, tmSerial, androidId;
    tmDevice = tm.getDeviceId().toString();
    tmSerial = "ANDROID_ID";
    androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID).toString();
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String uniqueId = deviceUuid.toString();
    return uniqueId;

}
ExampleUtil.java 文件源码 项目:JPush 阅读 30 收藏 0 点赞 0 评论 0
public static String getImei(Context context, String imei) {
    try {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();
    } catch (Exception e) {
        Log.e(ExampleUtil.class.getSimpleName(), e.getMessage());
    }
    return imei;
}
ccrccc.java 文件源码 项目:letv 阅读 23 收藏 0 点赞 0 评论 0
private void bйй0439043904390439() {
    if (this.bььь044Cьь.getPackageManager().checkPermission("android.permission.READ_PHONE_STATE", this.bььь044Cьь.getPackageName()) == 0) {
        TelephonyManager telephonyManager = (TelephonyManager) this.bььь044Cьь.getSystemService("phone");
        if (((b041EО041EО041EО() + b041E041EОО041EО) * b041EО041EО041EО()) % bОО041EО041EО != bО041EОО041EО) {
            b041EООО041EО = 81;
            bО041EОО041EО = b041EО041EО041EО();
        }
        this.b044Cь044Cььь = telephonyManager.getDeviceId();
    }
}
XNetworkUtils.java 文件源码 项目:XFrame 阅读 46 收藏 0 点赞 0 评论 0
/**
 * 打开或关闭移动数据(仅限系统应用)
 * <p>需系统应用 需添加权限{@code <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打开<br>{@code false}: 关闭
 */
public static void setDataEnabled(boolean enabled) {
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
        if (null != setMobileDataEnabledMethod) {
            setMobileDataEnabledMethod.invoke(tm, enabled);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
UAStateReceiver.java 文件源码 项目:CSipSimple 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Broadcast to android system that we currently have a phone call. This may
 * be managed by other sip apps that want to keep track of incoming calls
 * for example.
 * 
 * @param state The state of the call
 * @param number The corresponding remote number
 */
private void broadCastAndroidCallState(String state, String number) {
    // Android normalized event
    if(!Compatibility.isCompatible(19)) {
        // Not allowed to do that from kitkat
        Intent intent = new Intent(ACTION_PHONE_STATE_CHANGED);
        intent.putExtra(TelephonyManager.EXTRA_STATE, state);
        if (number != null) {
            intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, number);
        }
        intent.putExtra(pjService.service.getString(R.string.app_name), true);
        pjService.service.sendBroadcast(intent, android.Manifest.permission.READ_PHONE_STATE);
    }
}
CoreAndroid.java 文件源码 项目:DinningShare 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Listen for telephony events: RINGING, OFFHOOK and IDLE
 * Send these events to all plugins using
 *      CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
 */
private void initTelephonyReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    //final CordovaInterface mycordova = this.cordova;
    this.telephonyReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            // If state has changed
            if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
                    String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        LOG.i(TAG, "Telephone RINGING");
                        webView.getPluginManager().postMessage("telephone", "ringing");
                    }
                    else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        LOG.i(TAG, "Telephone OFFHOOK");
                        webView.getPluginManager().postMessage("telephone", "offhook");
                    }
                    else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        LOG.i(TAG, "Telephone IDLE");
                        webView.getPluginManager().postMessage("telephone", "idle");
                    }
                }
            }
        }
    };

    // Register the receiver
    webView.getContext().registerReceiver(this.telephonyReceiver, intentFilter);
}
XNetworkUtils.java 文件源码 项目:XFrame 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 判断移动数据是否打开
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean getDataEnabled() {
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Method getMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("getDataEnabled");
        if (null != getMobileDataEnabledMethod) {
            return (boolean) getMobileDataEnabledMethod.invoke(tm);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
MobileUtil.java 文件源码 项目:letv 阅读 19 收藏 0 点赞 0 评论 0
public static String getNetType(Context context) {
    String type = "network";
    if (context == null) {
        return type;
    }
    try {
        NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        if (networkInfo == null || !networkInfo.isAvailable()) {
            return "nont";
        }
        if (1 == networkInfo.getType()) {
            return "wifi";
        }
        switch (((TelephonyManager) context.getSystemService("phone")).getNetworkType()) {
            case 1:
            case 2:
            case 4:
                return "2g";
            case 13:
                return "4g";
            default:
                return "3g";
        }
    } catch (Exception e) {
        e.printStackTrace();
        return type;
    }
}
NetworkUtils.java 文件源码 项目:GitHub 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 打开或关闭移动数据
 * <p>需系统应用 需添加权限{@code <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打开<br>{@code false}: 关闭
 */
public static void setDataEnabled(final boolean enabled) {
    try {
        TelephonyManager tm = (TelephonyManager) Utils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
        Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
        if (null != setMobileDataEnabledMethod) {
            setMobileDataEnabledMethod.invoke(tm, enabled);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
AppUtils.java 文件源码 项目:androidtools 阅读 40 收藏 0 点赞 0 评论 0
/**
 * Access to mobile phone IMEI number, you need access to mobile phone information permissions.
 * [Manifest.permission.READ_PHONE_STATE]
 *
 * @param context context
 * @return mobile phone IMEI number
 */
public static String getIMEI(Context context) {
    String imei = null;
    if (checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();
    }
    return imei;
}


问题


面经


文章

微信
公众号

扫码关注公众号