title: Use TelephonyManager in fragment?
body: <p>I want to start and stop service when device in action call, so i use TelephonyManager and my class extends flagment. i Tried this code</p>
  
  <pre><code> TelephonyManager tm = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
          tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
  
  
      private PhoneStateListener mPhoneListener = new PhoneStateListener() {
      public void onCallStateChanged(int state, String incomingNumber) {
  
              switch (state) {
              case TelephonyManager.CALL_STATE_RINGING:
                  getActivity().stopService(new Intent(getActivity(),LockScreenService.class));
  
                  break;
  
              case TelephonyManager.CALL_STATE_OFFHOOK:
                  getActivity().stopService(new Intent(getActivity(),LockScreenService.class));
                  break;
  
              case TelephonyManager.CALL_STATE_IDLE:
                  getActivity().startService(new Intent(getActivity(),LockScreenService.class));
  
                  break;
  
              }
          } 
      } 
  ;
  </code></pre>
  
  <p>but it does not work. Please give me some advises. Thanks so much</p>