调用RequestInterruptionFilter后电话不响铃

时间:2018-01-14 22:05:53

标签: android android-phone-call notification-listener

我正在开发一个可以改变设备环形模式的应用程序。为此,我创建了一个NotificationListenerService,并在我的代码中调用requestInterruptionFilter来更改环模式。这里的一切都很棒!

现在,在我测试应用程序的时候,它出现了以下情况:我的手机上接到了一个电话,在我的应用程序设置INTERRUPTION_FILTER_ALL后很短的时间,但我的手机没有振铃。所以我在模拟器中尝试了相同的操作,我可以控制电话呼叫,它会出现同样的奇怪行为:当设置了INTERRUPTION_FILTER_ALARMS并且呼叫进来时我们设置INTERRUPTION_FILTER_ALL(之前)接听电话)电话没响。

您是否有任何想法如何在这种情况下手机振铃?

编辑:我当前的代码如下所示:

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();
            }
        }
    }
} 

0 个答案:

没有答案