Android Open Source - Silencer Incoming Call State Listener






From Project

Back to project page Silencer.

License

The source code is released under:

Apache License

If you think the Android project Silencer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ch3d.silencer;
/*from  w ww .  j a  v  a  2  s  .co m*/
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

import com.ch3d.silencer.service.CallSilencerService;

public class IncomingCallStateListener extends PhoneStateListener
{
    private final Context mContext;

    private boolean isIncoming;

    public IncomingCallStateListener(final Context context)
    {
        mContext = context;
    }

    @Override
    public void onCallStateChanged(final int state, final String incomingNumber)
    {
        switch (state)
        {
            case TelephonyManager.CALL_STATE_RINGING:
                isIncoming = true;
                mContext.startService(new Intent(mContext, CallSilencerService.class));
                break;

            case TelephonyManager.CALL_STATE_IDLE:
            case TelephonyManager.CALL_STATE_OFFHOOK:
                if (isIncoming)
                {
                    mContext.stopService(new Intent(mContext, CallSilencerService.class));
                    isIncoming = false;
                }
                break;

            default:
                break;
        }
    }
}




Java Source Code List

com.ch3d.silencer.CallReceiver.java
com.ch3d.silencer.IncomingCallStateListener.java
com.ch3d.silencer.SettingsActivity.java
com.ch3d.silencer.service.CallSilencerService.java