Last active
December 27, 2022 08:03
-
-
Save ParkSangGwon/c254676ecac3e4c0c3a9 to your computer and use it in GitHub Desktop.
전화가 걸려오는경우를 감지하고 전화번호 팝업으로 띄우기
This file contains 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 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