gpt4 book ai didi

android - 用户通过滑动将其删除后,在华为设备上重新启动前台通知(如 Strava/Endomondo)

转载 作者:搜寻专家 更新时间:2023-11-01 09:28:41 40 4
gpt4 key购买 nike

我有一个显示通知栏的前台任务,目的是让这个通知栏不可移动。通知的配置是:

Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Notification")
.setContentText("Notification for app")
.setSmallIcon(R.mipmap.ic_launcher)
.setContent(notificationView)
.setOngoing(true)
.build();

虽然应用了 setongoing(true),但可以在华为设备(Android 5.1.1)上删除通知。尽管它适用于三星 J3。

通知滑动时,华为出现如下画面

enter image description here

我在华为设备上的 strava/endomondo 应用程序上看到的情况是,它们会在用户滑动删除通知后立即恢复通知。

通知如何在用户删除后回到前台?

最佳答案

我终于可以像 strava/endomondo 那样在华为设备上重新启动通知了。

为了触发通知删除事件,我必须使用 setDeleteIntent 并传递接收器类的挂起 Intent 。

Intent intent = new Intent(this, BootCompleteReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0);

Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Foreground Task")
.setTicker("Notification")
.setContent(notificationView)
.setDeleteIntent(pendingIntent) //the delete intent I used
.setOngoing(true).build();

在receiver的onReceive方法上,我又开始了我的前台服务

    @Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, RTMForegroundService.class);
context.startService(service);
}

现在,每次用户滑动删除通知时,它都会重新开始。

关于android - 用户通过滑动将其删除后,在华为设备上重新启动前台通知(如 Strava/Endomondo),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49001145/

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