开发者

Notification question

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜