9

I'm currently working on an application which can change the ringmode of the device. For this I've created a NotificationListenerService and from my code I call requestInterruptionFilter to change between the ring modes. Everything here works great!

Now, while I was testing the application, it came to following situation: I got a call on my phone and short time after that my application set INTERRUPTION_FILTER_ALL but my phone wasn't ringing. So I tried the same in an emulator where I can control the phone calls and it comes to the same strange behavior: When i.e. INTERRUPTION_FILTER_ALARMS is set and a call is coming in and we then set INTERRUPTION_FILTER_ALL (before answering the call) the phone is not ringing.

Do you have any ideas how I can achieve that the phone is ringing in such situations?

EDIT: My current code looks like this:

public class NotificationService extends NotificationListenerService implements PhoneCallListener  {

    @Override
    public void onCreate() {
        super.onCreate();

        callReceiver = new CallReceiver(this);
        callReceiver.setListener(this);

        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_PHONE_STATE_CHANGED);

        registerReceiver(callReceiver, filter);
     }

     @Override
     public void onPhoneCallIncoming(String phoneNumber) {
         requestInterruptionFilter(INTERRUPTION_FILTER_ALL);
     }

     @Override
     public void onPhoneCallEnded() {
         Log.d("cilenco", "Phone call ended");
    }
}

public class CallReceiver extends BroadcastReceiver {

    public void setListener(PhoneCallListener listener) {
        this.listener = listener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if(ACTION_PHONE_STATE_CHANGED.equals(intent.getAction()) {
            String state = intent.getExtras().getString(EXTRA_STATE);
            String number = intent.getExtras().getString(EXTRA_INCOMING_NUMBER);

            if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
                listener.onPhoneCallIncoming(number);
            } else {
                 listener.onPhoneCallEnded();
            }
        }
    }
} 
Cilenco
  • 6,951
  • 17
  • 72
  • 152

0 Answers0