Created
February 23, 2014 20:52
-
-
Save DavidTPate/9177101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PhoneStateReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// Check phone state | |
String currentPhoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE); | |
// If the phone is ringing | |
if (currentPhoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) { | |
// If the phone is already in a call, ignore this call. | |
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); | |
switch (audioManager.getMode()) { | |
case AudioManager.MODE_IN_CALL: | |
return; | |
default: | |
break; | |
} | |
} | |
// If we should intercept the call, send it off to the IntentService since this will take some time. | |
context.startService(new Intent(context, PhoneAnswerIntentService.class)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment