How to Use PreciseCallState

后端 未结 2 829

I am making an App that should be able to detect call state, earlier I was advised to use PreciseCallState since by default android cannot detect exactly what s

2条回答
  •  庸人自扰
    2021-01-06 17:02

    try this,

    first of all you take permission like

    
    

    and then create receiver in manifest.xml file like,

    
        
            
        
    
    

    and implement onReceive() like this,

    public class OutCallLogger extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            switch (intent.getIntExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, -2) {
                case PreciseCallState.PRECISE_CALL_STATE_IDLE:
                    Log.d(This.LOG_TAG, "IDLE");
                    break;
                case PreciseCallState.PRECISE_CALL_STATE_DIALING:
                    Log.d(This.LOG_TAG, "DIALING");
                    break;
                case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
                    Log.d(This.LOG_TAG, "ALERTING");
                    break;
                case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
                    Log.d(This.LOG_TAG, "ACTIVE");
                    break;
            }
        }
    }
    

提交回复
热议问题