Question: 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

```
 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;

            }
        } 
    } 
;

```

but it does not work. Please give me some advises. Thanks so much

Answer: 
Try this code:

```
 telephonyManager  =  ( TelephonyManager )getActivity.getSystemService( Context.TELEPHONY_SERVICE );
 imeistring = telephonyManager.getDeviceId(); 

```
use Telephony manager inside your oncreate view