android - 通知问题

标签 android notifications

我想在通话时显示通知。
我已经完成了第一个简单的部分。当我的调用 Intent 开始时通知开始。
现在到了棘手的部分,我如何告诉我的通知电话已经结束?

最佳答案

您需要注册一个PhoneStateListenerTelephonyManager 上.

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

取消注册您的 PhoneStateListener:

tm.listen(phoneListener, PhoneStateListener.LISTEN_NONE);

关于android - 通知问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2311041/

相关文章:

java - 当给卡高程 ="0dp"时,CardBackgroundColor 无法工作

Android - 如果应用程序未运行,则 Pushbots NullpointerException

ios - 类型 'UITextField' 没有成员 'textDidBeginEditingNotification'

android - 服务定时器通知

android - AGP 3.5与Gradle 6兼容吗?

android - 我怎样才能获得这个UI结果?

Android - 执行异步任务的最佳方式

android - 如何在屏幕上的堆栈中添加多个 svg 图像?

iphone - 只让本地通知出现一次

php - laravel 5.3 - 在 Blade 模板中显示来自 mysql 文本字段的 json 数据