监听手机状态 网络,电话,位置等等~

mPhone = (TelephonyManager) this
                .getSystemService(Context.TELEPHONY_SERVICE);
        mPhone.listen(mPhoneStateListener,
                PhoneStateListener.LISTEN_SERVICE_STATE
                        | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                        | PhoneStateListener.LISTEN_DATA_ACTIVITY);

mPhoneStateListener = new PhoneStateListener() {

        @Override
        public void onDataActivity(int direction) {
            super.onDataActivity(direction);
            Log.v("kevin", "onDataActivity: " + direction);
        }

        @Override
        public void onDataConnectionStateChanged(int state) {
            super.onDataConnectionStateChanged(state);
            if(state == TelephonyManager.DATA_DISCONNECTED){
                Log.v("kevin", "onDataConnectionStateChanged: " + state);
            }
        }

        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            super.onServiceStateChanged(serviceState);
            Log.v("kevin", "onServiceStateChanged");
        }

    };
原文地址:https://www.cnblogs.com/yangzhenyu/p/2395191.html