我如何对通知关闭使用react?当某个通知被取消时,我需要终止我的后台进程。
在这个线程中它说使用广播接收器,但是没有用于通知的 intent-filter
最佳答案
如果您定义了手动触发类的 Intent,则不需要 intent-filter 来获取广播。
只需实现 BroadcastReceiver
public class NotificationDeleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// kill service here
}
}
并将Receiver添加到AndroidManifest.xml
<receiver android:name="NotificationDeleteReceiver" />
然后给通知设置PendingIndent:
notification.deleteIntent = PendingIntent.getBroadcast(
this, 0, new Intent(context, NotificationDeleteReceiver.class), 0);
这会起作用。
关于android - 我们如何检测通知取消?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18673155/