android电话事件详解

2019-04-13 21:32发布


android 电话来电、去电广播
拨打电话时,系统发出android.intent.action.NEW_OUTGOING_CALL广播: 来电时,系统没有发送对应的广播,但电话状态改变是会发送action为android.intent.action.PHONE_STATE的广播


添加权限:



public class EmergencyCallReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { System.out.println("action"+intent.getAction()); //如果是去电 if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){ String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Log.d(TAG, "call OUT:" + phoneNumber); }else{ //非去电即来电 } }