Skip to content

Instantly share code, notes, and snippets.

@ParkSangGwon
Last active December 27, 2022 08:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ParkSangGwon/c254676ecac3e4c0c3a9 to your computer and use it in GitHub Desktop.
Save ParkSangGwon/c254676ecac3e4c0c3a9 to your computer and use it in GitHub Desktop.
전화가 걸려오는경우를 감지하고 전화번호 팝업으로 띄우기
public class IncomingCallBroadcastReceiver extends BroadcastReceiver {
public static final String TAG = "PHONE STATE";
private static String mLastState;
private final Handler mHandler = new Handler(Looper.getMainLooper());
@Override
public void onReceive(final Context context, Intent intent) {
Log.d(TAG,"onReceive()");
/**
* http://mmarvick.github.io/blog/blog/lollipop-multiple-broadcastreceiver-call-state/
* 2번 호출되는 문제 해결
*/
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(mLastState)) {
return;
} else {
mLastState = state;
}
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
final String phone_number = PhoneNumberUtils.formatNumber(incomingNumber);
Intent serviceIntent = new Intent(context, CallingService.class);
serviceIntent.putExtra(CallingService.EXTRA_CALL_NUMBER, phone_number);
context.startService(serviceIntent);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment