<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 93,  comments - 2,  trackbacks - 0

    PhoneStateListener
    1.對特定的電話狀態的監聽,包括服務的狀態、信號強度、消息等待指示(語音信箱)、通話轉移、呼叫狀態、設備單元位置、數據連接狀態、數據流量方向。一些電話信息受權限保護,應用程序不會收到受保護的信息的更新,除非在manifest文件中有適當的權限聲明。凡申請許可,有適當的LISTEN_標志。

    2.對監聽的話做處理
    Handler mHandler = new Handler() {
       public void handleMessage(Message msg) {
           switch (msg.what) {
               case LISTEN_SERVICE_STATE:/*Listen for changes to the network service state (cellular).對網絡服務狀態監聽*/
                  PhoneStateListener.this.onServiceStateChanged((ServiceState)msg.obj);
                  break;
               case LISTEN_SIGNAL_STRENGTH:/*Listen for changes to the network signal strength (cellular).對網絡信號強度變化監聽*/
                  PhoneStateListener.this.onSignalStrengthChanged(msg.arg1);
                  break;
               case LISTEN_MESSAGE_WAITING_INDICATOR:/*Listen for changes to the message-waiting indicator.對消息等待指示的變化監聽*/
                  PhoneStateListener.this.onMessageWaitingIndicatorChanged(msg.arg1 != 0);
                  break;
               case LISTEN_CALL_FORWARDING_INDICATOR:/*Listen for changes to the call-forwarding indicator.對通話轉移指示的變化監聽*/
                  PhoneStateListener.this.onCallForwardingIndicatorChanged(msg.arg1 != 0);
                  break;
               case LISTEN_CELL_LOCATION:/*Listen for changes to the device's cell location. Note that this will result in frequent callbacks to the listener.對設備單元位置的變化監聽,這會導致頻繁的監聽回調。*/
                  PhoneStateListener.this.onCellLocationChanged((CellLocation)msg.obj);
                  break;
               case LISTEN_CALL_STATE:/*Listen for changes to the device call state.對設備呼叫狀態的變化監聽。*/
                  PhoneStateListener.this.onCallStateChanged(msg.arg1, (String)msg.obj);
                  break;
               case LISTEN_DATA_CONNECTION_STATE:/*Listen for changes to the data connection state (cellular).對數據連接狀態的變化監聽。*/
                  PhoneStateListener.this.onDataConnectionStateChanged(msg.arg1, msg.arg2);
                  PhoneStateListener.this.onDataConnectionStateChanged(msg.arg1);
                  break;
               case LISTEN_DATA_ACTIVITY:/*Listen for changes to the direction of data traffic on the data connection (cellular).對數據流量移動方向的變化監聽*/
                PhoneStateListener.this.onDataActivity(msg.arg1);
                  break;
               case LISTEN_SIGNAL_STRENGTHS:/*Listen for changes to the network signal strengths (cellular).對網絡信號強度的變化監聽*/
                  PhoneStateListener.this.onSignalStrengthsChanged((SignalStrength)msg.obj);
                  break;
          }
       }
    };

    3.監聽變化后發送消息
    IPhoneStateListener callback = new IPhoneStateListener.Stub() {
        public void onServiceStateChanged(ServiceState serviceState) {
            Message.obtain(mHandler, LISTEN_SERVICE_STATE, 0, 0, serviceState).sendToTarget();
        }
        public void onSignalStrengthChanged(int asu) {
            Message.obtain(mHandler, LISTEN_SIGNAL_STRENGTH, asu, 0, null).sendToTarget();
        }
        public void onMessageWaitingIndicatorChanged(boolean mwi) {
            Message.obtain(mHandler, LISTEN_MESSAGE_WAITING_INDICATOR, mwi ? 1 : 0, 0, null)
                    .sendToTarget();
        }
        public void onCallForwardingIndicatorChanged(boolean cfi) {
            Message.obtain(mHandler, LISTEN_CALL_FORWARDING_INDICATOR, cfi ? 1 : 0, 0, null)
                    .sendToTarget();
        }
        public void onCellLocationChanged(Bundle bundle) {
            CellLocation location = CellLocation.newFromBundle(bundle);
            Message.obtain(mHandler, LISTEN_CELL_LOCATION, 0, 0, location).sendToTarget();
        }
        public void onCallStateChanged(int state, String incomingNumber) {
            Message.obtain(mHandler, LISTEN_CALL_STATE, state, 0, incomingNumber).sendToTarget();
        }
        public void onDataConnectionStateChanged(int state, int networkType) {
            Message.obtain(mHandler, LISTEN_DATA_CONNECTION_STATE, state, networkType, null).
                    sendToTarget();
        }
        public void onDataActivity(int direction) {
            Message.obtain(mHandler, LISTEN_DATA_ACTIVITY, direction, 0, null).sendToTarget();
        }
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            Message.obtain(mHandler, LISTEN_SIGNAL_STRENGTHS, 0, 0, signalStrength).sendToTarget();
        }
    };

    posted on 2013-05-18 09:38 Terry Zou 閱讀(355) 評論(0)  編輯  收藏 所屬分類: Android
    <2013年5月>
    2829301234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    Java

    搜索

    •  

    最新隨筆

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 狠狠色伊人亚洲综合网站色| 成人性生活免费视频| 亚洲一级黄色大片| 亚洲一区欧洲一区| 成年免费a级毛片| 免费特级黄毛片在线成人观看| 亚洲国产综合自在线另类| 永久在线观看www免费视频| 亚洲人成电影福利在线播放| 亚洲人片在线观看天堂无码| 国产va免费精品观看精品| 日韩亚洲国产综合高清| 女人让男人免费桶爽30分钟| 亚洲精品色午夜无码专区日韩| 在线观看免费播放av片| 久久99国产亚洲精品观看| 羞羞视频免费观看| 伊人久久大香线蕉亚洲五月天 | 亚洲综合国产成人丁香五月激情 | 99国产精品视频免费观看| 久久亚洲AV无码精品色午夜| 无码免费又爽又高潮喷水的视频| 亚洲第一视频在线观看免费| 久久久久久久久久免免费精品| 久久精品a一国产成人免费网站 | 中文字幕亚洲日韩无线码| 精品国产免费一区二区三区香蕉| 亚洲高清美女一区二区三区| 好爽…又高潮了毛片免费看| 免费看美女午夜大片| 亚洲性天天干天天摸| 深夜福利在线免费观看| 亚洲中文字幕无码中文字在线| 最近免费mv在线电影| 亚洲精品无码国产片| 亚洲精品制服丝袜四区| 国产成人免费高清激情明星| 亚洲av丰满熟妇在线播放| 在线成人a毛片免费播放| 91av免费在线视频| 久久亚洲AV永久无码精品|