gpt4 book ai didi

android - Oreo Heads up 通知 - 如何检测/拦截用户滑动到状态栏的通知?

转载 作者:行者123 更新时间:2023-11-29 18:54:13 25 4
gpt4 key购买 nike

使用 NotificationCompat.Builder,我正在创建一个来电通知,PRIORITY_HIGH 通知,振动和持续设置为 true。

当调用 notify() 时,它还会启动铃声播放器,播放铃声。

目前这很完美。接听和拒绝操作工作正常,唯一的细微差别是如果您滑动通知,它会降级到状态栏(这很好)但我也希望铃声播放器在此时停止。

有什么方法可以告诉我,或者告诉我抬头通知已向上滑动到状态栏中?

在评论中回答已接受的答案。

通过使用 .setSound() 向构建器添加铃声解决了问题。谢谢A.A

最佳答案

您需要的是 deleteIntent

deleteIntent

The intent to execute when the notification is explicitly dismissed by the user, either with the "Clear All" button or by swiping it away individually. This probably shouldn't be launching an activity since several of those will be sent at the same time.

您可以将 PendingIntent 设置为 BroadcastReceiver,然后执行您想要的任何操作。

Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0);
Builder builder = new Notification.Builder(this):
builder.setDeleteIntent(pendingIntent);

对于 BroadcastReceiver

public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// stop your ringtone here
}
}

关于android - Oreo Heads up 通知 - 如何检测/拦截用户滑动到状态栏的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50255447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com