gpt4 book ai didi

java - 如何借助NotificationListnerService在通知中按下“标记为已读”按钮?

转载 作者:行者123 更新时间:2023-12-01 18:51:25 28 4
gpt4 key购买 nike

public class NotificationListenerExampleService extends NotificationListenerService {

@Override
public IBinder onBind(Intent intent) {
return super.onBind(intent);
}

@Override
public void onNotificationPosted(StatusBarNotification sbn){
//I am sucessfully Receiving Notification
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn){

}
}

我可以使用 onNotificationPosted() 读取通知内容。如何按通知中的“标记为已读”按钮?

最佳答案

after spending some time i am able to do that with the help of below code.

public class NotificationListenerExampleService extends 
NotificationListenerService {

@Override
public IBinder onBind(Intent intent) {
return super.onBind(intent);
}

@Override
public void onNotificationPosted(StatusBarNotification sbn){
//I am sucessfully Receiving Notification
try {

if (sbn.getNotification().actions != null) {
for (Notification.Action action: sbn.getNotification().actions) {

if (action.title.toString().equalsIgnoreCase("Mark as read")) {

PendingIntent intent = action.actionIntent;

try {
intent.send();
} catch(PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn){
}
}

关于java - 如何借助NotificationListnerService在通知中按下“标记为已读”按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59733204/

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