开发者

Notification question

开发者 https://www.devze.com 2022-12-21 01:38 出处:网络
I want to show a notification when a call is active. I have done the first easy part.Notification starts when my call intent starts.

I want to show a notification when a call is active.

I have done the first easy part. Notification starts when my call intent starts.

Now to the tricky part, how can I tell my Notific开发者_运维百科ation that the call has ended?


You need to register a PhoneStateListener on the TelephonyManager.

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

PhoneStateListener listener = new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        if (state == TelephonyManager.CALL_STATE_IDLE) {
            // hangup    
        }
    } 
};

tm.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

To unregister your PhoneStateListener:

tm.listen(phoneListener, PhoneStateListener.LISTEN_NONE);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号