Oreo Heads up notification - 如何检测/拦截用户滑动到状态栏的通知?
Oreo Heads up notification - how to detect/ intercept user swiping notification to status bar?
使用 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
}
}
使用 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
}
}