/** * Sets the current call state with the option to specify an incoming phone number for the * CALL_STATE_RINGING state. The incoming phone number will be ignored for all other cases. */ public void setCallState(int callState, String incomingPhoneNumber) { if (callState != CALL_STATE_RINGING) { incomingPhoneNumber = null; } this.callState = callState; this.incomingPhoneNumber = incomingPhoneNumber; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CALL_STATE)) { listener.onCallStateChanged(callState, incomingPhoneNumber); } }
private void initListener(PhoneStateListener listener, int flags) { if ((flags & LISTEN_CALL_STATE) != 0) { listener.onCallStateChanged(callState, incomingPhoneNumber); } if ((flags & LISTEN_CELL_INFO) != 0) { if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { listener.onCellInfoChanged(allCellInfo); } } if ((flags & LISTEN_CELL_LOCATION) != 0) { listener.onCellLocationChanged(cellLocation); } }
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.d(TAG, "PhoneStateListener: CALL_STATE_IDLE"); if (mMediaPlayer != null) { mMediaPlayer.start(); } break; case TelephonyManager.CALL_STATE_OFFHOOK: Log.d(TAG, "PhoneStateListener: CALL_STATE_OFFHOOK"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } break; case TelephonyManager.CALL_STATE_RINGING: Log.d(TAG, "PhoneStateListener: CALL_STATE_RINGING: " + incomingNumber); break; } } };
@Test public void testListenInit() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_CALL_STATE | LISTEN_CELL_INFO | LISTEN_CELL_LOCATION); verify(listener).onCallStateChanged(CALL_STATE_IDLE, null); verify(listener).onCellLocationChanged(null); if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { verify(listener).onCellInfoChanged(Collections.emptyList()); } }
@Test public void shouldGiveCallState() { PhoneStateListener listener = mock(PhoneStateListener.class); telephonyManager.listen(listener, LISTEN_CALL_STATE); shadowOf(telephonyManager).setCallState(CALL_STATE_RINGING, "911"); assertEquals(CALL_STATE_RINGING, telephonyManager.getCallState()); verify(listener).onCallStateChanged(CALL_STATE_RINGING, "911"); shadowOf(telephonyManager).setCallState(CALL_STATE_OFFHOOK, "911"); assertEquals(CALL_STATE_OFFHOOK, telephonyManager.getCallState()); verify(listener).onCallStateChanged(CALL_STATE_OFFHOOK, null); }
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); if (state == TelephonyManager.CALL_STATE_RINGING) { String phoneNumber = incomingNumber; } } }
public void setCallState(int callState, String incomingPhoneNumber) { if (callState != CALL_STATE_RINGING) { incomingPhoneNumber = null; } this.callState = callState; this.incomingPhoneNumber = incomingPhoneNumber; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CALL_STATE)) { listener.onCallStateChanged(callState, incomingPhoneNumber); } }
/** * Sets the current call state with the option to specify an incoming phone number for the * CALL_STATE_RINGING state. The incoming phone number will be ignored for all other cases. */ public void setCallState(int callState, String incomingPhoneNumber) { if (callState != CALL_STATE_RINGING) { incomingPhoneNumber = null; } this.callState = callState; this.incomingPhoneNumber = incomingPhoneNumber; for (PhoneStateListener listener : getListenersForFlags(LISTEN_CALL_STATE)) { listener.onCallStateChanged(callState, incomingPhoneNumber); } }
@Override public void onCallStateChanged(int state, String incomingNumber) { // TODO Auto-generated method stub //state 当前状态 incomingNumber,貌似没有去电的API super.onCallStateChanged(state, incomingNumber); Intent it = new Intent(); switch(state){ case TelephonyManager.CALL_STATE_IDLE: it.setAction("com.jiusg.mainscreenshow"); it.putExtra("msg", "call_stop"); context.sendBroadcast(it); break; case TelephonyManager.CALL_STATE_OFFHOOK: it.setAction("com.jiusg.mainscreenshow"); it.putExtra("msg", "call_start"); context.sendBroadcast(it); break; case TelephonyManager.CALL_STATE_RINGING: // System.out.println("响铃:来电号码"+incomingNumber); it.setAction("com.jiusg.mainscreenshow"); it.putExtra("msg", "call_ring"); context.sendBroadcast(it); //输出来电号码 break; } } };
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: hideNotification(); break; case TelephonyManager.CALL_STATE_OFFHOOK: showNotification(incomingNumber); if (!"".equals(incomingNumber)) { SharedPreferences callpreference = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = callpreference.edit(); editor.putString("number", incomingNumber); editor.commit(); } break; } System.out.println("incomingNumber : " + incomingNumber); } }, PhoneStateListener.LISTEN_CALL_STATE);
private void initListener(PhoneStateListener listener, int flags) { if ((flags & LISTEN_CALL_STATE) != 0) { listener.onCallStateChanged(callState, incomingPhoneNumber); } if ((flags & LISTEN_CELL_INFO) != 0) { if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { listener.onCellInfoChanged(allCellInfo); } } if ((flags & LISTEN_CELL_LOCATION) != 0) { listener.onCellLocationChanged(cellLocation); } }
@Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { if (audioStreamingManager.isPlaying()) { audioStreamingManager.handlePauseRequest(); } } else if (state == TelephonyManager.CALL_STATE_IDLE) { } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) { } super.onCallStateChanged(state, incomingNumber); } };
private void initListener(PhoneStateListener listener, int flags) { if ((flags & LISTEN_CALL_STATE) != 0) { listener.onCallStateChanged(callState, incomingPhoneNumber); } if ((flags & LISTEN_CELL_INFO) != 0) { if (VERSION.SDK_INT >= JELLY_BEAN_MR1) { listener.onCellInfoChanged(allCellInfo); } } if ((flags & LISTEN_CELL_LOCATION) != 0) { listener.onCellLocationChanged(cellLocation); } }
@Override public void onCallStateChanged(int state, String incomingNumber) { if( state == TelephonyManager.CALL_STATE_RINGING ) { INSTANCE.pause(); } else if( state == TelephonyManager.CALL_STATE_IDLE ) { if (!Game.instance.isPaused()) { INSTANCE.resume(); } } super.onCallStateChanged(state, incomingNumber); } };
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_RINGING: if (Aware.DEBUG) Log.d(TAG, ACTION_AWARE_CALL_RINGING); Intent callRinging = new Intent(ACTION_AWARE_CALL_RINGING); sendBroadcast(callRinging); if (awareSensor != null) awareSensor.onRinging(incomingNumber); break; case TelephonyManager.CALL_STATE_OFFHOOK: if (Aware.DEBUG) Log.d(TAG, ACTION_AWARE_USER_IN_CALL); Intent inCall = new Intent(ACTION_AWARE_USER_IN_CALL); sendBroadcast(inCall); if (awareSensor != null) awareSensor.onBusy(incomingNumber); break; case TelephonyManager.CALL_STATE_IDLE: if (Aware.DEBUG) Log.d(TAG, ACTION_AWARE_USER_NOT_IN_CALL); Intent userFree = new Intent(ACTION_AWARE_USER_NOT_IN_CALL); sendBroadcast(userFree); if (awareSensor != null) awareSensor.onFree(incomingNumber); break; } } }
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: // hide location floatToast.close(); break; case TelephonyManager.CALL_STATE_OFFHOOK: { if(outgoing) {// if the CALL_STATE_OFFHOOK is outgoing call, don't hide it until CALL_STATE_IDLE outgoing = false; break; } // hide location floatToast.close(); break; } case TelephonyManager.CALL_STATE_RINGING: { showLocation(incomingNumber); break; } } } };
@Override public void onCallStateChanged(int state, final String incomingNumber) { super.onCallStateChanged(state, incomingNumber);
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) {