통보가 울리면 알림 소리를 내고 싶지 않습니다. 알림 소리가 나고 전화가 울리면 알림 소리를 멈추어야합니다.전화 통보 상태로 통보
다음 코드를 시도했지만 현재 전화 상태를 가져올 수 없습니다.
TelephonyManager telephonyManager = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new CustomPhoneStateListener(context),
PhoneStateListener.LISTEN_CALL_STATE);
public class CustomPhoneStateListener extends PhoneStateListener {
//private static final String TAG = "PhoneStateChanged";
Context context; //Context to make Toast if required
public CustomPhoneStateListener(Context context) {
super();
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
//when Idle i.e no call
Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//when Off hook i.e in call
//Make intent and start your service here
Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
//when Ringing
Toast.makeText(context, "Phone state Ringing", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}
안녕하세요 @masoudVali 내가 다른 사용자에게 전화 할 때 어떤 상태가됩니까? –
도움을 주셔서 감사합니다. 코드가 잘 작동합니다. –
이 'intent.getAction(). equals (Intent.ACTION_NEW_OUTGOING_CALL)'에 의해 발신 전화를 확인할 수 있습니다. –