Skip to content

Instantly share code, notes, and snippets.

@DavidTPate
Created February 23, 2014 20:52
Show Gist options
  • Save DavidTPate/9177101 to your computer and use it in GitHub Desktop.
Save DavidTPate/9177101 to your computer and use it in GitHub Desktop.
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